Change in openvpn[master]: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH ...
A message that is not in the archive (sent off-list or not yet received): gerrit.1732124549000.I6ecd4cb47571cc8c20e46de8595c742aeec6064a@...2715...
Attention is currently required from: flichtenheld, plaisthos.
Hello plaisthos, flichtenheld,
I'd like you to do a code review.
Please visit
http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
to review the following change.
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
* Added IV_PROTO_PUSH_UPDATE flag bit to support push-updates.
* Added process_incoming_push_update(), in a separate file to create tests more easily.
* Modified incoming_push_message(), process_incoming_push_msg(), apply_push_options(), apply_pull_filter() to process also push-update messages.
* Added the check_push_update_option_flags() function used in apply_pull_filter() to check options formatting inside push-update messages, if the options are updatables and to check for '?' and '-' flags that may be present in front of the options. The '-' flag is used to indicate that the option in question should be removed, while the '?' indicates that the option is optional and to do not generate errors if the client cannot update that option.
For more info you can read the RFC at https://github.com/OpenVPN/openvpn-rfc .
* Created some unit tests for the push-update message handling in test_push_update_msg.c.
---
M CMakeLists.txt
M src/openvpn/Makefile.am
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/options_util.c
M src/openvpn/options_util.h
M src/openvpn/push.c
M src/openvpn/push.h
A src/openvpn/push_util.c
M src/openvpn/ssl.c
M src/openvpn/ssl.h
M tests/unit_tests/openvpn/Makefile.am
A tests/unit_tests/openvpn/test_push_update_msg.c
15 files changed, 611 insertions(+), 82 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/08/808/1
CMakeLists.txt +1 -0
@@ -496,6 +496,7 @@ src/openvpn/ps.c src/openvpn/ps.h src/openvpn/push.c + src/openvpn/push_util.c src/openvpn/push.h src/openvpn/pushlist.h src/openvpn/reflect_filter.c
src/openvpn/Makefile.am +1 -1
@@ -114,7 +114,7 @@ proto.c proto.h \ proxy.c proxy.h \ ps.c ps.h \ - push.c push.h \ + push.c push_util.c push.h \ pushlist.h \ reflect_filter.c reflect_filter.h \ reliable.c reliable.h \
src/openvpn/forward.c +1 -1
@@ -2031,7 +2031,7 @@ }/* check for incoming control messages on the control channel like -* push request/reply, or authentication failure and 2FA messages */ +* push request/reply/update, or authentication failure and 2FA messages */ if (tls_test_payload_len (c->c2.tls_multi) >0 ) {check_incoming_control_channel (c);
src/openvpn/init.c +2 -2
@@ -2030,8 +2030,8 @@/* possibly add routes */ if ((route_order (c->c1.tuntap) ==ROUTE_AFTER_TUN ) && (!c->options.route_delay_defined)) { -int status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); +bool status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); *error_flags |= (status ?0 :ISC_ROUTE_ERRORS ); }
src/openvpn/options.c +38 -66
128 lines not on this page · raw message
src/openvpn/options.h +31 -2
@@ -777,6 +777,33 @@#define MAN_CLIENT_AUTH_ENABLED (opt) (false)#endif +/* +* some PUSH_UPDATE options +*/ +#define OPT_P_U_ROUTE (1<<0) +#define OPT_P_U_ROUTE6 (1<<1) +#define OPT_P_U_DNS (1<<2) +#define OPT_P_U_DHCP (1<<3) +#define OPT_P_U_REDIR_GATEWAY (1<<4) + +struct pull_filter +{ +#define PUF_TYPE_UNDEF 0/** undefined filter type */ +#define PUF_TYPE_ACCEPT 1/** filter type to accept a matching option */ +#define PUF_TYPE_IGNORE 2/** filter type to ignore a matching option */ +#define PUF_TYPE_REJECT 3/** filter type to reject and trigger SIGUSR1 */ +int type; +int size; +char *pattern; +struct pull_filter *next; +}; + +struct pull_filter_list +{ +struct pull_filter *head; +struct pull_filter *tail; +}; + void parse_argv(struct options *options, const int argc, char *argv[],
@@ -845,11 +872,13 @@void pre_connect_restore (struct options *o,struct gc_arena *gc); -bool apply_push_options (struct options *options, +bool apply_push_options (struct context *c, +struct options *options,struct buffer *buf,unsigned int permission_mask,unsigned int *option_types_found, -struct env_set *es); +struct env_set *es, +bool is_update);void options_detach (struct options *o);
src/openvpn/options_util.c +175 -0
184 lines not on this page · raw message
src/openvpn/options_util.h +6 -0
@@ -30,4 +30,10 @@const char *parse_auth_failed_temp (struct options *o,const char *reason); +bool +apply_pull_filter (const struct options *o, +char *line, +bool is_update, +unsigned int *push_update_option_flags); +#endif
src/openvpn/push.c +25 -9
@@ -39,8 +39,6 @@#include "ssl_util.h" #include "options_util.h" -static char push_reply_cmd[] ="PUSH_REPLY" ; -/* * Auth username/password *
@@ -519,21 +517,31 @@ {msg (D_PUSH_ERRORS ,"WARNING: Received bad push/pull message: %s" ,sanitize_control_message (BSTR (buffer), &gc)); } - else if (status == PUSH_MSG_REPLY || status == PUSH_MSG_CONTINUATION) + else if (status == PUSH_MSG_REPLY || status == PUSH_MSG_UPDATE || status == PUSH_MSG_CONTINUATION) { c->options.push_option_types_found |= option_types_found;/* delay bringing tun/tap up until --push parms received from remote */ -if (status ==PUSH_MSG_REPLY ) +if (status ==PUSH_MSG_REPLY || status ==PUSH_MSG_UPDATE ) {if (!options_postprocess_pull (&c->options, c->c2.es)) { goto error; } -if (!do_up (c, true, c->options.push_option_types_found)) +if (status ==PUSH_MSG_REPLY ) { -msg (D_PUSH_ERRORS ,"Failed to open tun/tap interface" ); - goto error; +if (!do_up (c, true, c->options.push_option_types_found)) + { +msg (D_PUSH_ERRORS ,"Failed to open tun/tap interface" ); + goto error; + } + } +else + { +if (!option_types_found) + { +msg (M_WARN ,"No option found" ); + } } }event_timeout_clear (&c->c2.push_request_interval);
@@ -1048,11 +1056,13 @@md_ctx_init (c->c2.pulled_options_state,"SHA256" ); c->c2.pulled_options_digest_init_done = true; } -if (apply_push_options (&c->options, +if (apply_push_options (c, + &c->options, buf, permission_mask, option_types_found, - c->c2.es)) + c->c2.es, + false)) {push_update_digest (c->c2.pulled_options_state, &buf_orig, &c->options);
@@ -1103,6 +1113,12 @@return process_incoming_push_reply (c, permission_mask, option_types_found, &buf); } +else if (honor_received_options + &&buf_string_compare_advance (&buf, push_update_cmd)) + { +return process_incoming_push_update (c, permission_mask, + option_types_found, &buf); + }else {return PUSH_MSG_ERROR ;
src/openvpn/push.h +13 -0
@@ -33,9 +33,22 @@#define PUSH_MSG_AUTH_FAILURE 4#define PUSH_MSG_CONTINUATION 5#define PUSH_MSG_ALREADY_REPLIED 6 +#define PUSH_MSG_UPDATE 7 + +#define push_reply_cmd "PUSH_REPLY" +#define push_update_cmd "PUSH_UPDATE" + +/* Push-update options flags */ +#define PUSH_OPT_TO_REMOVE (1<<0) +#define PUSH_OPT_OPTIONAL (1<<1)int process_incoming_push_request (struct context *c); +int process_incoming_push_update (struct context *c, +unsigned int permission_mask, +unsigned int *option_types_found, +struct buffer *buf); + int process_incoming_push_msg(struct context *c, const struct buffer *buffer, bool honor_received_options,
src/openvpn/push_util.c new file +44 -0
44 lines not on this page · raw message
src/openvpn/ssl.c +3 -0
@@ -1947,6 +1947,9 @@/* support for exit notify via control channel */ iv_proto |=IV_PROTO_CC_EXIT_NOTIFY ; +/* support push-updates */ + iv_proto |=IV_PROTO_PUSH_UPDATE ; +if (session->opt->pull) {/* support for receiving push_reply before sending
src/openvpn/ssl.h +3 -0
@@ -110,6 +110,9 @@/** Supports the --dns option after all the incompatible changes */ #define IV_PROTO_DNS_OPTION_V2 (1<<11) +/** Supports push-update */ +#define IV_PROTO_PUSH_UPDATE (1<<12) +/* Default field in X509 to be username */ #define X509_USERNAME_FIELD_DEFAULT "CN"
tests/unit_tests/openvpn/Makefile.am +23 -1
@@ -11,7 +11,7 @@ endif test_binaries += crypto_testdriver packet_id_testdriver auth_token_testdriver ncp_testdriver misc_testdriver \ - pkt_testdriver ssl_testdriver user_pass_testdriver + pkt_testdriver ssl_testdriver user_pass_testdriver push_update_msg_testdriver if HAVE_LD_WRAP_SUPPORT if !WIN32
@@ -307,3 +307,25 @@ $(top_srcdir)/src/openvpn/win32-util.c \ $(top_srcdir)/src/openvpn/platform.c \ $(top_srcdir)/src/openvpn/list.c + +push_update_msg_testdriver_CFLAGS = -I$(top_srcdir)/src/openvpn \ + -I$(top_srcdir)/src/compat \ + -I$(top_srcdir)/tests/unit_tests/openvpn \ + -ffunction-sections \ + @TEST_CFLAGS@ \ + @CMOCKA_CFLAGS@ + +push_update_msg_testdriver_LDFLAGS = \ + @TEST_LDFLAGS@ \ + @CMOCKA_LIBS@ \ + -L$(top_srcdir)/src/openvpn \ + $(OPTIONAL_CRYPTO_LIBS) + +push_update_msg_testdriver_SOURCES = test_push_update_msg.c \ + mock_msg.c \ + mock_get_random.c \ + $(top_srcdir)/src/openvpn/buffer.c \ + $(top_srcdir)/src/openvpn/platform.c \ + $(top_srcdir)/src/openvpn/push_util.c \ + $(top_srcdir)/src/openvpn/options_util.c \ + $(top_srcdir)/src/openvpn/otime.c
tests/unit_tests/openvpn/test_push_update_msg.c new file +245 -0
245 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 1
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newchange
Attention is currently required from: flichtenheld, plaisthos.
mrbff has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/808?usp=email )
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
Patch Set 1: Code-Review+2
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 1
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: mrbff <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Thu, 21 Nov 2024 11:20:55 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: mrbff, plaisthos.
flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/808?usp=email )
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
Patch Set 1: Code-Review-1
(2 comments)
File src/openvpn/options.c:
http://gerrit.openvpn.net/c/openvpn/+/808/comment/f6e72862_6ae239a4 :
PS1, Line 5472: if (!apply_pull_filter(options, line))
```
options.c: In function ‘apply_push_options’:
options.c:5472:14: error: too few arguments to function ‘apply_pull_filter’
5472 | if (!apply_pull_filter(options, line))
| ^~~~~~~~~~~~~~~~~
In file included from options.c:66:
options_util.h:34:1: note: declared here
34 | apply_pull_filter(const struct options *o,
| ^~~~~~~~~~~~~~~~~
```http://gerrit.openvpn.net/c/openvpn/+/808/comment/09d1a5a6_ed8662d7 :
PS1, Line 5618: apply_push_options(struct context *c,
```
options.c:5456:1: error: conflicting types for ‘apply_push_options’; have ‘_Bool(struct options *, struct buffer *, unsigned int, unsigned int *, struct env_set *)’
5456 | apply_push_options(struct options *options,
| ^~~~~~~~~~~~~~~~~~
In file included from ssl.h:40,
from options.c:45:
options.h:875:6: note: previous declaration of ‘apply_push_options’ with type ‘_Bool(struct context *, struct options *, struct buffer *, unsigned int, unsigned int *, struct env_set *, _Bool)’
875 | bool apply_push_options(struct context *c,
| ^~~~~~~~~~~~~~~~~~
```--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 1
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: mrbff <[email protected]...>
Gerrit-Comment-Date: Thu, 21 Nov 2024 13:10:07 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, mrbff, plaisthos.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
to look at the new patch set (#2).
The following approvals got outdated and were removed:
Code-Review-1 by flichtenheld
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
* Added IV_PROTO_PUSH_UPDATE flag bit to support push-updates.
* Added process_incoming_push_update(), in a separate file to create tests more easily.
* Modified incoming_push_message(), process_incoming_push_msg(), apply_push_options(), apply_pull_filter() to process also push-update messages.
* Added the check_push_update_option_flags() function used in apply_pull_filter() to check options formatting inside push-update messages, if the options are updatables and to check for '?' and '-' flags that may be present in front of the options. The '-' flag is used to indicate that the option in question should be removed, while the '?' indicates that the option is optional and to do not generate errors if the client cannot update that option.
For more info you can read the RFC at https://github.com/OpenVPN/openvpn-rfc .
* Created some unit tests for the push-update message handling in test_push_update_msg.c.
---
M CMakeLists.txt
M src/openvpn/Makefile.am
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/options_util.c
M src/openvpn/options_util.h
M src/openvpn/push.c
M src/openvpn/push.h
A src/openvpn/push_util.c
M src/openvpn/ssl.c
M src/openvpn/ssl.h
M tests/unit_tests/openvpn/Makefile.am
A tests/unit_tests/openvpn/test_push_update_msg.c
15 files changed, 612 insertions(+), 112 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/08/808/2
CMakeLists.txt +1 -0
@@ -496,6 +496,7 @@ src/openvpn/ps.c src/openvpn/ps.h src/openvpn/push.c + src/openvpn/push_util.c src/openvpn/push.h src/openvpn/pushlist.h src/openvpn/reflect_filter.c
src/openvpn/Makefile.am +1 -1
@@ -114,7 +114,7 @@ proto.c proto.h \ proxy.c proxy.h \ ps.c ps.h \ - push.c push.h \ + push.c push_util.c push.h \ pushlist.h \ reflect_filter.c reflect_filter.h \ reliable.c reliable.h \
src/openvpn/forward.c +1 -1
@@ -2031,7 +2031,7 @@ }/* check for incoming control messages on the control channel like -* push request/reply, or authentication failure and 2FA messages */ +* push request/reply/update, or authentication failure and 2FA messages */ if (tls_test_payload_len (c->c2.tls_multi) >0 ) {check_incoming_control_channel (c);
src/openvpn/init.c +2 -2
@@ -2030,8 +2030,8 @@/* possibly add routes */ if ((route_order (c->c1.tuntap) ==ROUTE_AFTER_TUN ) && (!c->options.route_delay_defined)) { -int status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); +bool status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); *error_flags |= (status ?0 :ISC_ROUTE_ERRORS ); }
src/openvpn/options.c +39 -96
159 lines not on this page · raw message
src/openvpn/options.h +31 -2
@@ -777,6 +777,33 @@#define MAN_CLIENT_AUTH_ENABLED (opt) (false)#endif +/* +* some PUSH_UPDATE options +*/ +#define OPT_P_U_ROUTE (1<<0) +#define OPT_P_U_ROUTE6 (1<<1) +#define OPT_P_U_DNS (1<<2) +#define OPT_P_U_DHCP (1<<3) +#define OPT_P_U_REDIR_GATEWAY (1<<4) + +struct pull_filter +{ +#define PUF_TYPE_UNDEF 0/** undefined filter type */ +#define PUF_TYPE_ACCEPT 1/** filter type to accept a matching option */ +#define PUF_TYPE_IGNORE 2/** filter type to ignore a matching option */ +#define PUF_TYPE_REJECT 3/** filter type to reject and trigger SIGUSR1 */ +int type; +int size; +char *pattern; +struct pull_filter *next; +}; + +struct pull_filter_list +{ +struct pull_filter *head; +struct pull_filter *tail; +}; + void parse_argv(struct options *options, const int argc, char *argv[],
@@ -845,11 +872,13 @@void pre_connect_restore (struct options *o,struct gc_arena *gc); -bool apply_push_options (struct options *options, +bool apply_push_options (struct context *c, +struct options *options,struct buffer *buf,unsigned int permission_mask,unsigned int *option_types_found, -struct env_set *es); +struct env_set *es, +bool is_update);void options_detach (struct options *o);
src/openvpn/options_util.c +175 -0
184 lines not on this page · raw message
src/openvpn/options_util.h +6 -0
@@ -30,4 +30,10 @@const char *parse_auth_failed_temp (struct options *o,const char *reason); +bool +apply_pull_filter (const struct options *o, +char *line, +bool is_update, +unsigned int *push_update_option_flags); +#endif
src/openvpn/push.c +25 -9
@@ -39,8 +39,6 @@#include "ssl_util.h" #include "options_util.h" -static char push_reply_cmd[] ="PUSH_REPLY" ; -/* * Auth username/password *
@@ -519,21 +517,31 @@ {msg (D_PUSH_ERRORS ,"WARNING: Received bad push/pull message: %s" ,sanitize_control_message (BSTR (buffer), &gc)); } - else if (status == PUSH_MSG_REPLY || status == PUSH_MSG_CONTINUATION) + else if (status == PUSH_MSG_REPLY || status == PUSH_MSG_UPDATE || status == PUSH_MSG_CONTINUATION) { c->options.push_option_types_found |= option_types_found;/* delay bringing tun/tap up until --push parms received from remote */ -if (status ==PUSH_MSG_REPLY ) +if (status ==PUSH_MSG_REPLY || status ==PUSH_MSG_UPDATE ) {if (!options_postprocess_pull (&c->options, c->c2.es)) { goto error; } -if (!do_up (c, true, c->options.push_option_types_found)) +if (status ==PUSH_MSG_REPLY ) { -msg (D_PUSH_ERRORS ,"Failed to open tun/tap interface" ); - goto error; +if (!do_up (c, true, c->options.push_option_types_found)) + { +msg (D_PUSH_ERRORS ,"Failed to open tun/tap interface" ); + goto error; + } + } +else + { +if (!option_types_found) + { +msg (M_WARN ,"No option found" ); + } } }event_timeout_clear (&c->c2.push_request_interval);
@@ -1048,11 +1056,13 @@md_ctx_init (c->c2.pulled_options_state,"SHA256" ); c->c2.pulled_options_digest_init_done = true; } -if (apply_push_options (&c->options, +if (apply_push_options (c, + &c->options, buf, permission_mask, option_types_found, - c->c2.es)) + c->c2.es, + false)) {push_update_digest (c->c2.pulled_options_state, &buf_orig, &c->options);
@@ -1103,6 +1113,12 @@return process_incoming_push_reply (c, permission_mask, option_types_found, &buf); } +else if (honor_received_options + &&buf_string_compare_advance (&buf, push_update_cmd)) + { +return process_incoming_push_update (c, permission_mask, + option_types_found, &buf); + }else {return PUSH_MSG_ERROR ;
src/openvpn/push.h +13 -0
@@ -33,9 +33,22 @@#define PUSH_MSG_AUTH_FAILURE 4#define PUSH_MSG_CONTINUATION 5#define PUSH_MSG_ALREADY_REPLIED 6 +#define PUSH_MSG_UPDATE 7 + +#define push_reply_cmd "PUSH_REPLY" +#define push_update_cmd "PUSH_UPDATE" + +/* Push-update options flags */ +#define PUSH_OPT_TO_REMOVE (1<<0) +#define PUSH_OPT_OPTIONAL (1<<1)int process_incoming_push_request (struct context *c); +int process_incoming_push_update (struct context *c, +unsigned int permission_mask, +unsigned int *option_types_found, +struct buffer *buf); + int process_incoming_push_msg(struct context *c, const struct buffer *buffer, bool honor_received_options,
src/openvpn/push_util.c new file +44 -0
44 lines not on this page · raw message
src/openvpn/ssl.c +3 -0
@@ -1947,6 +1947,9 @@/* support for exit notify via control channel */ iv_proto |=IV_PROTO_CC_EXIT_NOTIFY ; +/* support push-updates */ + iv_proto |=IV_PROTO_PUSH_UPDATE ; +if (session->opt->pull) {/* support for receiving push_reply before sending
src/openvpn/ssl.h +3 -0
@@ -110,6 +110,9 @@/** Supports the --dns option after all the incompatible changes */ #define IV_PROTO_DNS_OPTION_V2 (1<<11) +/** Supports push-update */ +#define IV_PROTO_PUSH_UPDATE (1<<12) +/* Default field in X509 to be username */ #define X509_USERNAME_FIELD_DEFAULT "CN"
tests/unit_tests/openvpn/Makefile.am +23 -1
@@ -11,7 +11,7 @@ endif test_binaries += crypto_testdriver packet_id_testdriver auth_token_testdriver ncp_testdriver misc_testdriver \ - pkt_testdriver ssl_testdriver user_pass_testdriver + pkt_testdriver ssl_testdriver user_pass_testdriver push_update_msg_testdriver if HAVE_LD_WRAP_SUPPORT if !WIN32
@@ -307,3 +307,25 @@ $(top_srcdir)/src/openvpn/win32-util.c \ $(top_srcdir)/src/openvpn/platform.c \ $(top_srcdir)/src/openvpn/list.c + +push_update_msg_testdriver_CFLAGS = -I$(top_srcdir)/src/openvpn \ + -I$(top_srcdir)/src/compat \ + -I$(top_srcdir)/tests/unit_tests/openvpn \ + -ffunction-sections \ + @TEST_CFLAGS@ \ + @CMOCKA_CFLAGS@ + +push_update_msg_testdriver_LDFLAGS = \ + @TEST_LDFLAGS@ \ + @CMOCKA_LIBS@ \ + -L$(top_srcdir)/src/openvpn \ + $(OPTIONAL_CRYPTO_LIBS) + +push_update_msg_testdriver_SOURCES = test_push_update_msg.c \ + mock_msg.c \ + mock_get_random.c \ + $(top_srcdir)/src/openvpn/buffer.c \ + $(top_srcdir)/src/openvpn/platform.c \ + $(top_srcdir)/src/openvpn/push_util.c \ + $(top_srcdir)/src/openvpn/options_util.c \ + $(top_srcdir)/src/openvpn/otime.c
tests/unit_tests/openvpn/test_push_update_msg.c new file +245 -0
245 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 2
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mrbff <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld, plaisthos.
mrbff has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/808?usp=email )
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
Patch Set 2:
(2 comments)
File src/openvpn/options.c:
http://gerrit.openvpn.net/c/openvpn/+/808/comment/63c77cf9_f80c96b7 :
PS1, Line 5472: if (!apply_pull_filter(options, line))
Quoted 1 line
``` […]
Done
http://gerrit.openvpn.net/c/openvpn/+/808/comment/b168825e_5aab5102 :
PS1, Line 5618: apply_push_options(struct context *c,
Quoted 1 line
``` […]
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 2
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Thu, 21 Nov 2024 18:30:19 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: mrbff, plaisthos.
flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/808?usp=email )
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
Patch Set 3: Code-Review-1
(1 comment)
File src/openvpn/options.c:
http://gerrit.openvpn.net/c/openvpn/+/808/comment/0907cbe2_3aee602b :
PS3, Line 932: #define PUF_TYPE_UNDEF 0 /** undefined filter type */
Needs rebase on top of 6c636f5387245ceb4809eac765c4b649709b4aa8
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 3
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: mrbff <[email protected]...>
Gerrit-Comment-Date: Tue, 26 Nov 2024 17:31:15 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: mrbff, plaisthos.
flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/808?usp=email )
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
Patch Set 3:
(1 comment)
File tests/unit_tests/openvpn/Makefile.am:
http://gerrit.openvpn.net/c/openvpn/+/808/comment/09ca4a05_8807ae01 :
PS3, Line 14: pkt_testdriver ssl_testdriver user_pass_testdriver push_update_msg_testdriver
Please also add this test to CMakeLists.txt
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 3
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: mrbff <[email protected]...>
Gerrit-Comment-Date: Tue, 26 Nov 2024 17:40:07 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, mrbff, plaisthos.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
to look at the new patch set (#4).
The following approvals got outdated and were removed:
Code-Review-1 by flichtenheld
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
* Added IV_PROTO_PUSH_UPDATE flag bit to support push-updates.
* Added process_incoming_push_update(), in a separate file to create tests more easily.
* Modified incoming_push_message(), process_incoming_push_msg(), apply_push_options(), apply_pull_filter() to process also push-update messages.
* Added the check_push_update_option_flags() function used in apply_pull_filter() to check options formatting inside push-update messages, if the options are updatables and to check for '?' and '-' flags that may be present in front of the options. The '-' flag is used to indicate that the option in question should be removed, while the '?' indicates that the option is optional and to do not generate errors if the client cannot update that option.
For more info you can read the RFC at https://github.com/OpenVPN/openvpn-rfc .
* Created some unit tests for the push-update message handling in test_push_update_msg.c.
---
M CMakeLists.txt
M src/openvpn/Makefile.am
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/options_util.c
M src/openvpn/options_util.h
M src/openvpn/push.c
M src/openvpn/push.h
A src/openvpn/push_util.c
M src/openvpn/ssl.c
M src/openvpn/ssl.h
M tests/unit_tests/openvpn/Makefile.am
A tests/unit_tests/openvpn/test_push_update_msg.c
15 files changed, 619 insertions(+), 112 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/08/808/4
CMakeLists.txt +12 -0
@@ -496,6 +496,7 @@ src/openvpn/ps.c src/openvpn/ps.h src/openvpn/push.c + src/openvpn/push_util.c src/openvpn/push.h src/openvpn/pushlist.h src/openvpn/reflect_filter.c
@@ -612,6 +613,7 @@ "test_provider" "test_ssl" "test_user_pass" + "test_push_update_msg" ) if (WIN32)
@@ -807,6 +809,16 @@ src/openvpn/env_set.c src/openvpn/run_command.c ) + + target_sources(test_push_update_msg PRIVATE + tests/unit_tests/openvpn/mock_msg.c + tests/unit_tests/openvpn/mock_get_random.c + src/openvpn/buffer.c + src/openvpn/platform.c + src/openvpn/push_util.c + src/openvpn/options_util.c + src/openvpn/otime.c + ) if (TARGET test_argv) target_link_options(test_argv PRIVATE -Wl,--wrap=parse_line)
src/openvpn/Makefile.am +1 -1
@@ -114,7 +114,7 @@ proto.c proto.h \ proxy.c proxy.h \ ps.c ps.h \ - push.c push.h \ + push.c push_util.c push.h \ pushlist.h \ reflect_filter.c reflect_filter.h \ reliable.c reliable.h \
src/openvpn/forward.c +1 -1
@@ -2031,7 +2031,7 @@ }/* check for incoming control messages on the control channel like -* push request/reply, or authentication failure and 2FA messages */ +* push request/reply/update, or authentication failure and 2FA messages */ if (tls_test_payload_len (c->c2.tls_multi) >0 ) {check_incoming_control_channel (c);
src/openvpn/init.c +2 -2
@@ -2030,8 +2030,8 @@/* possibly add routes */ if ((route_order (c->c1.tuntap) ==ROUTE_AFTER_TUN ) && (!c->options.route_delay_defined)) { -int status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); +bool status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); *error_flags |= (status ?0 :ISC_ROUTE_ERRORS ); }
src/openvpn/options.c +39 -96
159 lines not on this page · raw message
src/openvpn/options.h +31 -2
@@ -777,6 +777,33 @@#define MAN_CLIENT_AUTH_ENABLED (opt) (false)#endif +/* +* some PUSH_UPDATE options +*/ +#define OPT_P_U_ROUTE (1<<0) +#define OPT_P_U_ROUTE6 (1<<1) +#define OPT_P_U_DNS (1<<2) +#define OPT_P_U_DHCP (1<<3) +#define OPT_P_U_REDIR_GATEWAY (1<<4) + +struct pull_filter +{ +#define PUF_TYPE_UNDEF 0/** undefined filter type */ +#define PUF_TYPE_ACCEPT 1/** filter type to accept a matching option */ +#define PUF_TYPE_IGNORE 2/** filter type to ignore a matching option */ +#define PUF_TYPE_REJECT 3/** filter type to reject and trigger SIGUSR1 */ +int type; +int size; +char *pattern; +struct pull_filter *next; +}; + +struct pull_filter_list +{ +struct pull_filter *head; +struct pull_filter *tail; +}; + void parse_argv(struct options *options, const int argc, char *argv[],
@@ -845,11 +872,13 @@void pre_connect_restore (struct options *o,struct gc_arena *gc); -bool apply_push_options (struct options *options, +bool apply_push_options (struct context *c, +struct options *options,struct buffer *buf,unsigned int permission_mask,unsigned int *option_types_found, -struct env_set *es); +struct env_set *es, +bool is_update);void options_detach (struct options *o);
src/openvpn/options_util.c +175 -0
184 lines not on this page · raw message
src/openvpn/options_util.h +6 -0
@@ -30,4 +30,10 @@const char *parse_auth_failed_temp (struct options *o,const char *reason); +bool +apply_pull_filter (const struct options *o, +char *line, +bool is_update, +unsigned int *push_update_option_flags); +#endif
src/openvpn/push.c +25 -9
@@ -39,8 +39,6 @@#include "ssl_util.h" #include "options_util.h" -static char push_reply_cmd[] ="PUSH_REPLY" ; -/* * Auth username/password *
@@ -519,21 +517,31 @@ {msg (D_PUSH_ERRORS ,"WARNING: Received bad push/pull message: %s" ,sanitize_control_message (BSTR (buffer), &gc)); } - else if (status == PUSH_MSG_REPLY || status == PUSH_MSG_CONTINUATION) + else if (status == PUSH_MSG_REPLY || status == PUSH_MSG_UPDATE || status == PUSH_MSG_CONTINUATION) { c->options.push_option_types_found |= option_types_found;/* delay bringing tun/tap up until --push parms received from remote */ -if (status ==PUSH_MSG_REPLY ) +if (status ==PUSH_MSG_REPLY || status ==PUSH_MSG_UPDATE ) {if (!options_postprocess_pull (&c->options, c->c2.es)) { goto error; } -if (!do_up (c, true, c->options.push_option_types_found)) +if (status ==PUSH_MSG_REPLY ) { -msg (D_PUSH_ERRORS ,"Failed to open tun/tap interface" ); - goto error; +if (!do_up (c, true, c->options.push_option_types_found)) + { +msg (D_PUSH_ERRORS ,"Failed to open tun/tap interface" ); + goto error; + } + } +else + { +if (!option_types_found) + { +msg (M_WARN ,"No option found" ); + } } }event_timeout_clear (&c->c2.push_request_interval);
@@ -1048,11 +1056,13 @@md_ctx_init (c->c2.pulled_options_state,"SHA256" ); c->c2.pulled_options_digest_init_done = true; } -if (apply_push_options (&c->options, +if (apply_push_options (c, + &c->options, buf, permission_mask, option_types_found, - c->c2.es)) + c->c2.es, + false)) {push_update_digest (c->c2.pulled_options_state, &buf_orig, &c->options);
@@ -1103,6 +1113,12 @@return process_incoming_push_reply (c, permission_mask, option_types_found, &buf); } +else if (honor_received_options + &&buf_string_compare_advance (&buf, push_update_cmd)) + { +return process_incoming_push_update (c, permission_mask, + option_types_found, &buf); + }else {return PUSH_MSG_ERROR ;
src/openvpn/push.h +13 -0
@@ -33,9 +33,22 @@#define PUSH_MSG_AUTH_FAILURE 4#define PUSH_MSG_CONTINUATION 5#define PUSH_MSG_ALREADY_REPLIED 6 +#define PUSH_MSG_UPDATE 7 + +#define push_reply_cmd "PUSH_REPLY" +#define push_update_cmd "PUSH_UPDATE" + +/* Push-update options flags */ +#define PUSH_OPT_TO_REMOVE (1<<0) +#define PUSH_OPT_OPTIONAL (1<<1)int process_incoming_push_request (struct context *c); +int process_incoming_push_update (struct context *c, +unsigned int permission_mask, +unsigned int *option_types_found, +struct buffer *buf); + int process_incoming_push_msg(struct context *c, const struct buffer *buffer, bool honor_received_options,
src/openvpn/push_util.c new file +44 -0
44 lines not on this page · raw message
src/openvpn/ssl.c +3 -0
@@ -1947,6 +1947,9 @@/* support for exit notify via control channel */ iv_proto |=IV_PROTO_CC_EXIT_NOTIFY ; +/* support push-updates */ + iv_proto |=IV_PROTO_PUSH_UPDATE ; +if (session->opt->pull) {/* support for receiving push_reply before sending
src/openvpn/ssl.h +3 -0
@@ -110,6 +110,9 @@/** Supports the --dns option after all the incompatible changes */ #define IV_PROTO_DNS_OPTION_V2 (1<<11) +/** Supports push-update */ +#define IV_PROTO_PUSH_UPDATE (1<<12) +/* Default field in X509 to be username */ #define X509_USERNAME_FIELD_DEFAULT "CN"
tests/unit_tests/openvpn/Makefile.am +19 -1
@@ -11,7 +11,7 @@ endif test_binaries += crypto_testdriver packet_id_testdriver auth_token_testdriver ncp_testdriver misc_testdriver \ - pkt_testdriver ssl_testdriver user_pass_testdriver + pkt_testdriver ssl_testdriver user_pass_testdriver push_update_msg_testdriver if HAVE_LD_WRAP_SUPPORT if !WIN32
@@ -307,3 +307,21 @@ $(top_srcdir)/src/openvpn/win32-util.c \ $(top_srcdir)/src/openvpn/platform.c \ $(top_srcdir)/src/openvpn/list.c + +push_update_msg_testdriver_CFLAGS = -I$(top_srcdir)/src/openvpn \ + -I$(top_srcdir)/src/compat \ + -I$(top_srcdir)/tests/unit_tests/openvpn \ + @TEST_CFLAGS@ + +push_update_msg_testdriver_LDFLAGS = \ + @TEST_LDFLAGS@ \ + -L$(top_srcdir)/src/openvpn + +push_update_msg_testdriver_SOURCES = test_push_update_msg.c \ + mock_msg.c \ + mock_get_random.c \ + $(top_srcdir)/src/openvpn/buffer.c \ + $(top_srcdir)/src/openvpn/platform.c \ + $(top_srcdir)/src/openvpn/push_util.c \ + $(top_srcdir)/src/openvpn/options_util.c \ + $(top_srcdir)/src/openvpn/otime.c
tests/unit_tests/openvpn/test_push_update_msg.c new file +245 -0
245 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 4
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mrbff <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld, plaisthos.
mrbff has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/808?usp=email )
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
Patch Set 4:
(2 comments)
File src/openvpn/options.c:
http://gerrit.openvpn.net/c/openvpn/+/808/comment/4631a9b8_d330a116 :
PS3, Line 932: #define PUF_TYPE_UNDEF 0 /** undefined filter type */
Quoted 1 line
Needs rebase on top of
6c636f5387245ceb4809eac765c4b649709b4aa8
Done
File tests/unit_tests/openvpn/Makefile.am:
http://gerrit.openvpn.net/c/openvpn/+/808/comment/bbdd5cb5_f48d4c7c :
PS3, Line 14: pkt_testdriver ssl_testdriver user_pass_testdriver push_update_msg_testdriver
Quoted 1 line
Please also add this test to CMakeLists. […]
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 4
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Wed, 27 Nov 2024 10:45:33 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, mrbff, plaisthos.
stipa has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/808?usp=email )
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
Patch Set 4:
(7 comments)
File CMakeLists.txt:
http://gerrit.openvpn.net/c/openvpn/+/808/comment/6208a664_8a387af8 :
PS4, Line 812:
nit: whitespace
File src/openvpn/init.c:
http://gerrit.openvpn.net/c/openvpn/+/808/comment/4862d3bd_9b57ad9f :
PS4, Line 2033: int status = do_route(&c->options, c->c1.route_list, c->c1.route_ipv6_list,
nice catch!
File src/openvpn/options_util.c:
http://gerrit.openvpn.net/c/openvpn/+/808/comment/93ec136c_da93606f :
PS4, Line 124: check_push_update_option_flags(char **line, unsigned int *flags) Add doxygen what does this function do.
http://gerrit.openvpn.net/c/openvpn/+/808/comment/cacb7fd2_2e6844f7 :
PS4, Line 138: if (str[1])
below 8 lines are duplicated 3 times. Maybe define a macro and reuse it, and later undefine? Like
#define ADVANCE_OR_FAIL(ptr) \
do { \
if (!(ptr)[1]) \
return false; \
c = *(++(ptr)); \
} while (0)http://gerrit.openvpn.net/c/openvpn/+/808/comment/fc0ee113_1823490a :
PS4, Line 160: if (c == '-' && !(*flags & PUSH_OPT_TO_REMOVE))
you could remove the "c == '-'" check here and move this whole block under the "if" condition above
http://gerrit.openvpn.net/c/openvpn/+/808/comment/76877514_402d6e34 :
PS4, Line 221: apply_pull_filter(const struct options *o, char *line, bool is_update, unsigned int *push_update_option_flags) Let's move doxygen to the header.
File src/openvpn/push.h:
http://gerrit.openvpn.net/c/openvpn/+/808/comment/811984a2_89dbae3b :
PS4, Line 47: int process_incoming_push_update(struct context *c, Doxygen
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 4
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: stipa <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mrbff <[email protected]...>
Gerrit-Comment-Date: Wed, 27 Nov 2024 11:41:18 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
Attention is currently required from: mrbff, plaisthos.
flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/808?usp=email )
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
Patch Set 4: Code-Review-1
(2 comments)
File CMakeLists.txt:
http://gerrit.openvpn.net/c/openvpn/+/808/comment/cd014878_336b1231 :
PS4, Line 817: src/openvpn/platform.cbuffer.c and platform.c are always added by foreach loop above. So they are redundant here.
File src/openvpn/options.h:
http://gerrit.openvpn.net/c/openvpn/+/808/comment/654dd17f_91aed2e0 :
PS4, Line 791: #define PUF_TYPE_UNDEF 0 /** undefined filter type */
You didn't resolve the conflict correctly when rebasing. Please copy the new code here.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 4
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: stipa <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: mrbff <[email protected]...>
Gerrit-Comment-Date: Thu, 28 Nov 2024 09:52:42 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, mrbff, plaisthos.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
to look at the new patch set (#5).
The following approvals got outdated and were removed:
Code-Review-1 by flichtenheld
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
* Added IV_PROTO_PUSH_UPDATE flag bit to support push-updates.
* Added process_incoming_push_update(), in a separate file to create tests more easily.
* Modified incoming_push_message(), process_incoming_push_msg(), apply_push_options(), apply_pull_filter() to process also push-update messages.
* Added the check_push_update_option_flags() function used in apply_pull_filter() to check options formatting inside push-update messages, if the options are updatables and to check for '?' and '-' flags that may be present in front of the options. The '-' flag is used to indicate that the option in question should be removed, while the '?' indicates that the option is optional and to do not generate errors if the client cannot update that option.
For more info you can read the RFC at https://github.com/OpenVPN/openvpn-rfc .
* Created some unit tests for the push-update message handling in test_push_update_msg.c.
---
M CMakeLists.txt
M src/openvpn/Makefile.am
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/options_util.c
M src/openvpn/options_util.h
M src/openvpn/push.c
M src/openvpn/push.h
A src/openvpn/push_util.c
M src/openvpn/ssl.c
M src/openvpn/ssl.h
M tests/unit_tests/openvpn/Makefile.am
A tests/unit_tests/openvpn/test_push_update_msg.c
15 files changed, 645 insertions(+), 112 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/08/808/5
CMakeLists.txt +12 -0
@@ -496,6 +496,7 @@ src/openvpn/ps.c src/openvpn/ps.h src/openvpn/push.c + src/openvpn/push_util.c src/openvpn/push.h src/openvpn/pushlist.h src/openvpn/reflect_filter.c
@@ -612,6 +613,7 @@ "test_provider" "test_ssl" "test_user_pass" + "test_push_update_msg" ) if (WIN32)
@@ -808,6 +810,16 @@ src/openvpn/run_command.c ) + target_sources(test_push_update_msg PRIVATE + tests/unit_tests/openvpn/mock_msg.c + tests/unit_tests/openvpn/mock_get_random.c + src/openvpn/buffer.c + src/openvpn/platform.c + src/openvpn/push_util.c + src/openvpn/options_util.c + src/openvpn/otime.c + ) + if (TARGET test_argv) target_link_options(test_argv PRIVATE -Wl,--wrap=parse_line) target_sources(test_argv PRIVATE
src/openvpn/Makefile.am +1 -1
@@ -114,7 +114,7 @@ proto.c proto.h \ proxy.c proxy.h \ ps.c ps.h \ - push.c push.h \ + push.c push_util.c push.h \ pushlist.h \ reflect_filter.c reflect_filter.h \ reliable.c reliable.h \
src/openvpn/forward.c +1 -1
@@ -2031,7 +2031,7 @@ }/* check for incoming control messages on the control channel like -* push request/reply, or authentication failure and 2FA messages */ +* push request/reply/update, or authentication failure and 2FA messages */ if (tls_test_payload_len (c->c2.tls_multi) >0 ) {check_incoming_control_channel (c);
src/openvpn/init.c +2 -2
@@ -2030,8 +2030,8 @@/* possibly add routes */ if ((route_order (c->c1.tuntap) ==ROUTE_AFTER_TUN ) && (!c->options.route_delay_defined)) { -int status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); +bool status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); *error_flags |= (status ?0 :ISC_ROUTE_ERRORS ); }
src/openvpn/options.c +39 -96
159 lines not on this page · raw message
src/openvpn/options.h +31 -2
@@ -777,6 +777,33 @@#define MAN_CLIENT_AUTH_ENABLED (opt) (false)#endif +/* +* some PUSH_UPDATE options +*/ +#define OPT_P_U_ROUTE (1<<0) +#define OPT_P_U_ROUTE6 (1<<1) +#define OPT_P_U_DNS (1<<2) +#define OPT_P_U_DHCP (1<<3) +#define OPT_P_U_REDIR_GATEWAY (1<<4) + +struct pull_filter +{ +#define PUF_TYPE_UNDEF 0/** undefined filter type */ +#define PUF_TYPE_ACCEPT 1/** filter type to accept a matching option */ +#define PUF_TYPE_IGNORE 2/** filter type to ignore a matching option */ +#define PUF_TYPE_REJECT 3/** filter type to reject and trigger SIGUSR1 */ +int type; +int size; +char *pattern; +struct pull_filter *next; +}; + +struct pull_filter_list +{ +struct pull_filter *head; +struct pull_filter *tail; +}; + void parse_argv(struct options *options, const int argc, char *argv[],
@@ -845,11 +872,13 @@void pre_connect_restore (struct options *o,struct gc_arena *gc); -bool apply_push_options (struct options *options, +bool apply_push_options (struct context *c, +struct options *options,struct buffer *buf,unsigned int permission_mask,unsigned int *option_types_found, -struct env_set *es); +struct env_set *es, +bool is_update);void options_detach (struct options *o);
src/openvpn/options_util.c +173 -0
182 lines not on this page · raw message
src/openvpn/options_util.h +14 -0
@@ -30,4 +30,18 @@const char *parse_auth_failed_temp (struct options *o,const char *reason); +/** +* Filter an option line by all pull filters. +* +* If a match is found, the line is modified depending on +* the filter type, and returns true. If the filter type is +* reject, SIGUSR1 is triggered and the return value is false. +* In that case the caller must end the push processing. +*/ +bool +apply_pull_filter (const struct options *o, +char *line, +bool is_update, +unsigned int *push_update_option_flags); +#endif
src/openvpn/push.c +25 -9
@@ -39,8 +39,6 @@#include "ssl_util.h" #include "options_util.h" -static char push_reply_cmd[] ="PUSH_REPLY" ; -/* * Auth username/password *
@@ -519,21 +517,31 @@ {msg (D_PUSH_ERRORS ,"WARNING: Received bad push/pull message: %s" ,sanitize_control_message (BSTR (buffer), &gc)); } - else if (status == PUSH_MSG_REPLY || status == PUSH_MSG_CONTINUATION) + else if (status == PUSH_MSG_REPLY || status == PUSH_MSG_UPDATE || status == PUSH_MSG_CONTINUATION) { c->options.push_option_types_found |= option_types_found;/* delay bringing tun/tap up until --push parms received from remote */ -if (status ==PUSH_MSG_REPLY ) +if (status ==PUSH_MSG_REPLY || status ==PUSH_MSG_UPDATE ) {if (!options_postprocess_pull (&c->options, c->c2.es)) { goto error; } -if (!do_up (c, true, c->options.push_option_types_found)) +if (status ==PUSH_MSG_REPLY ) { -msg (D_PUSH_ERRORS ,"Failed to open tun/tap interface" ); - goto error; +if (!do_up (c, true, c->options.push_option_types_found)) + { +msg (D_PUSH_ERRORS ,"Failed to open tun/tap interface" ); + goto error; + } + } +else + { +if (!option_types_found) + { +msg (M_WARN ,"No option found" ); + } } }event_timeout_clear (&c->c2.push_request_interval);
@@ -1048,11 +1056,13 @@md_ctx_init (c->c2.pulled_options_state,"SHA256" ); c->c2.pulled_options_digest_init_done = true; } -if (apply_push_options (&c->options, +if (apply_push_options (c, + &c->options, buf, permission_mask, option_types_found, - c->c2.es)) + c->c2.es, + false)) {push_update_digest (c->c2.pulled_options_state, &buf_orig, &c->options);
@@ -1103,6 +1113,12 @@return process_incoming_push_reply (c, permission_mask, option_types_found, &buf); } +else if (honor_received_options + &&buf_string_compare_advance (&buf, push_update_cmd)) + { +return process_incoming_push_update (c, permission_mask, + option_types_found, &buf); + }else {return PUSH_MSG_ERROR ;
src/openvpn/push.h +33 -0
@@ -33,9 +33,42 @@#define PUSH_MSG_AUTH_FAILURE 4#define PUSH_MSG_CONTINUATION 5#define PUSH_MSG_ALREADY_REPLIED 6 +#define PUSH_MSG_UPDATE 7 + +#define push_reply_cmd "PUSH_REPLY" +#define push_update_cmd "PUSH_UPDATE" + +/* Push-update options flags */ +#define PUSH_OPT_TO_REMOVE (1<<0) +#define PUSH_OPT_OPTIONAL (1<<1)int process_incoming_push_request (struct context *c); +/** +* @brief Handles the receiving of a push-update message and applies updates to the specified options. +* +* This function processes a push-update message, validating its content and applying updates +* to the options specified in the message. It also handles split messages if the complete +* message has not yet been received. +* +* @param c The context for the operation. +* @param permission_mask The permission mask specifying which options are allowed to be pulled. +* @param option_types_found A pointer to a variable that will be filled with the types of options +* found in the message. +* @param buf A buffer containing the received message. +* +* @return +* - `PUSH_MSG_UPDATE`: The message was processed successfully, and the updates were applied. +* - `PUSH_MSG_CONTINUATION`: The message is a fragment of a larger message, and the program is +* waiting for the final part. +* - `PUSH_MSG_ERROR`: An error occurred during message processing, or the message is invalid. +*/ + +int process_incoming_push_update (struct context *c, +unsigned int permission_mask, +unsigned int *option_types_found, +struct buffer *buf); + int process_incoming_push_msg(struct context *c, const struct buffer *buffer, bool honor_received_options,
src/openvpn/push_util.c new file +44 -0
44 lines not on this page · raw message
src/openvpn/ssl.c +3 -0
@@ -1947,6 +1947,9 @@/* support for exit notify via control channel */ iv_proto |=IV_PROTO_CC_EXIT_NOTIFY ; +/* support push-updates */ + iv_proto |=IV_PROTO_PUSH_UPDATE ; +if (session->opt->pull) {/* support for receiving push_reply before sending
src/openvpn/ssl.h +3 -0
@@ -110,6 +110,9 @@/** Supports the --dns option after all the incompatible changes */ #define IV_PROTO_DNS_OPTION_V2 (1<<11) +/** Supports push-update */ +#define IV_PROTO_PUSH_UPDATE (1<<12) +/* Default field in X509 to be username */ #define X509_USERNAME_FIELD_DEFAULT "CN"
tests/unit_tests/openvpn/Makefile.am +19 -1
@@ -11,7 +11,7 @@ endif test_binaries += crypto_testdriver packet_id_testdriver auth_token_testdriver ncp_testdriver misc_testdriver \ - pkt_testdriver ssl_testdriver user_pass_testdriver + pkt_testdriver ssl_testdriver user_pass_testdriver push_update_msg_testdriver if HAVE_LD_WRAP_SUPPORT if !WIN32
@@ -307,3 +307,21 @@ $(top_srcdir)/src/openvpn/win32-util.c \ $(top_srcdir)/src/openvpn/platform.c \ $(top_srcdir)/src/openvpn/list.c + +push_update_msg_testdriver_CFLAGS = -I$(top_srcdir)/src/openvpn \ + -I$(top_srcdir)/src/compat \ + -I$(top_srcdir)/tests/unit_tests/openvpn \ + @TEST_CFLAGS@ + +push_update_msg_testdriver_LDFLAGS = \ + @TEST_LDFLAGS@ \ + -L$(top_srcdir)/src/openvpn + +push_update_msg_testdriver_SOURCES = test_push_update_msg.c \ + mock_msg.c \ + mock_get_random.c \ + $(top_srcdir)/src/openvpn/buffer.c \ + $(top_srcdir)/src/openvpn/platform.c \ + $(top_srcdir)/src/openvpn/push_util.c \ + $(top_srcdir)/src/openvpn/options_util.c \ + $(top_srcdir)/src/openvpn/otime.c
tests/unit_tests/openvpn/test_push_update_msg.c new file +245 -0
245 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 5
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: stipa <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mrbff <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld, plaisthos, stipa.
mrbff has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/808?usp=email )
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
Patch Set 5:
(7 comments)
File CMakeLists.txt:
http://gerrit.openvpn.net/c/openvpn/+/808/comment/8f5a6f36_8362c01a :
PS4, Line 812:
Quoted 1 line
nit: whitespace
Done
File src/openvpn/init.c:
http://gerrit.openvpn.net/c/openvpn/+/808/comment/bd8dd262_1158ed00 :
PS4, Line 2033: int status = do_route(&c->options, c->c1.route_list, c->c1.route_ipv6_list,
Quoted 1 line
nice catch!
tnx!
File src/openvpn/options_util.c:
http://gerrit.openvpn.net/c/openvpn/+/808/comment/f8c35b78_8f40c7a2 :
PS4, Line 124: check_push_update_option_flags(char **line, unsigned int *flags)
Quoted 1 line
Add doxygen what does this function do.
Done
http://gerrit.openvpn.net/c/openvpn/+/808/comment/a0c306fd_1444ca21 :
PS4, Line 138: if (str[1])
Quoted 1 line
below 8 lines are duplicated 3 times. Maybe define a macro and reuse it, and later undefine? Like […]
Clever, i like it, I tried but when the compiler optimizes it, the code gets skipped. Anyway, i simplified and now i use it just 2 times and with a slightly different condition so i hope is good enough
http://gerrit.openvpn.net/c/openvpn/+/808/comment/a517e1a9_3a38d88f :
PS4, Line 160: if (c == '-' && !(*flags & PUSH_OPT_TO_REMOVE))
Quoted 1 line
you could remove the "c == '-'" check here and move this whole block under the "if" condition above
I'm not entirely sure that's what you meant but I simplified
http://gerrit.openvpn.net/c/openvpn/+/808/comment/ada8cdcc_81c709fb :
PS4, Line 221: apply_pull_filter(const struct options *o, char *line, bool is_update, unsigned int *push_update_option_flags)
Quoted 1 line
Let's move doxygen to the header.
Done
File src/openvpn/push.h:
http://gerrit.openvpn.net/c/openvpn/+/808/comment/276f3131_7f2768f9 :
PS4, Line 47: int process_incoming_push_update(struct context *c,
Quoted 1 line
Doxygen
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 5
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: stipa <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Thu, 28 Nov 2024 15:21:49 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: stipa <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, plaisthos, stipa.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
to look at the new patch set (#6).
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
* Added IV_PROTO_PUSH_UPDATE flag bit to support push-updates.
* Added process_incoming_push_update(), in a separate file to create tests more easily.
* Modified incoming_push_message(), process_incoming_push_msg(), apply_push_options(), apply_pull_filter() to process also push-update messages.
* Added the check_push_update_option_flags() function used in apply_pull_filter() to check options formatting inside push-update messages, if the options are updatables and to check for '?' and '-' flags that may be present in front of the options. The '-' flag is used to indicate that the option in question should be removed, while the '?' indicates that the option is optional and to do not generate errors if the client cannot update that option.
For more info you can read the RFC at https://github.com/OpenVPN/openvpn-rfc .
* Created some unit tests for the push-update message handling in test_push_update_msg.c.
---
M CMakeLists.txt
M src/openvpn/Makefile.am
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/options_util.c
M src/openvpn/options_util.h
M src/openvpn/push.c
M src/openvpn/push.h
A src/openvpn/push_util.c
M src/openvpn/ssl.c
M src/openvpn/ssl.h
M tests/unit_tests/openvpn/Makefile.am
A tests/unit_tests/openvpn/test_push_update_msg.c
15 files changed, 643 insertions(+), 112 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/08/808/6
CMakeLists.txt +10 -0
@@ -496,6 +496,7 @@ src/openvpn/ps.c src/openvpn/ps.h src/openvpn/push.c + src/openvpn/push_util.c src/openvpn/push.h src/openvpn/pushlist.h src/openvpn/reflect_filter.c
@@ -612,6 +613,7 @@ "test_provider" "test_ssl" "test_user_pass" + "test_push_update_msg" ) if (WIN32)
@@ -808,6 +810,14 @@ src/openvpn/run_command.c ) + target_sources(test_push_update_msg PRIVATE + tests/unit_tests/openvpn/mock_msg.c + tests/unit_tests/openvpn/mock_get_random.c + src/openvpn/push_util.c + src/openvpn/options_util.c + src/openvpn/otime.c + ) + if (TARGET test_argv) target_link_options(test_argv PRIVATE -Wl,--wrap=parse_line) target_sources(test_argv PRIVATE
src/openvpn/Makefile.am +1 -1
@@ -114,7 +114,7 @@ proto.c proto.h \ proxy.c proxy.h \ ps.c ps.h \ - push.c push.h \ + push.c push_util.c push.h \ pushlist.h \ reflect_filter.c reflect_filter.h \ reliable.c reliable.h \
src/openvpn/forward.c +1 -1
@@ -2031,7 +2031,7 @@ }/* check for incoming control messages on the control channel like -* push request/reply, or authentication failure and 2FA messages */ +* push request/reply/update, or authentication failure and 2FA messages */ if (tls_test_payload_len (c->c2.tls_multi) >0 ) {check_incoming_control_channel (c);
src/openvpn/init.c +2 -2
@@ -2030,8 +2030,8 @@/* possibly add routes */ if ((route_order (c->c1.tuntap) ==ROUTE_AFTER_TUN ) && (!c->options.route_delay_defined)) { -int status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); +bool status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); *error_flags |= (status ?0 :ISC_ROUTE_ERRORS ); }
src/openvpn/options.c +39 -96
159 lines not on this page · raw message
src/openvpn/options.h +31 -2
@@ -777,6 +777,33 @@#define MAN_CLIENT_AUTH_ENABLED (opt) (false)#endif +/* +* some PUSH_UPDATE options +*/ +#define OPT_P_U_ROUTE (1<<0) +#define OPT_P_U_ROUTE6 (1<<1) +#define OPT_P_U_DNS (1<<2) +#define OPT_P_U_DHCP (1<<3) +#define OPT_P_U_REDIR_GATEWAY (1<<4) + +struct pull_filter +{ +#define PUF_TYPE_UNDEF 0/**< undefined filter type */ +#define PUF_TYPE_ACCEPT 1/**< filter type to accept a matching option */ +#define PUF_TYPE_IGNORE 2/**< filter type to ignore a matching option */ +#define PUF_TYPE_REJECT 3/**< filter type to reject and trigger SIGUSR1 */ +int type; +int size; +char *pattern; +struct pull_filter *next; +}; + +struct pull_filter_list +{ +struct pull_filter *head; +struct pull_filter *tail; +}; + void parse_argv(struct options *options, const int argc, char *argv[],
@@ -845,11 +872,13 @@void pre_connect_restore (struct options *o,struct gc_arena *gc); -bool apply_push_options (struct options *options, +bool apply_push_options (struct context *c, +struct options *options,struct buffer *buf,unsigned int permission_mask,unsigned int *option_types_found, -struct env_set *es); +struct env_set *es, +bool is_update);void options_detach (struct options *o);
src/openvpn/options_util.c +173 -0
182 lines not on this page · raw message
src/openvpn/options_util.h +14 -0
@@ -30,4 +30,18 @@const char *parse_auth_failed_temp (struct options *o,const char *reason); +/** +* Filter an option line by all pull filters. +* +* If a match is found, the line is modified depending on +* the filter type, and returns true. If the filter type is +* reject, SIGUSR1 is triggered and the return value is false. +* In that case the caller must end the push processing. +*/ +bool +apply_pull_filter (const struct options *o, +char *line, +bool is_update, +unsigned int *push_update_option_flags); +#endif
src/openvpn/push.c +25 -9
@@ -39,8 +39,6 @@#include "ssl_util.h" #include "options_util.h" -static char push_reply_cmd[] ="PUSH_REPLY" ; -/* * Auth username/password *
@@ -519,21 +517,31 @@ {msg (D_PUSH_ERRORS ,"WARNING: Received bad push/pull message: %s" ,sanitize_control_message (BSTR (buffer), &gc)); } - else if (status == PUSH_MSG_REPLY || status == PUSH_MSG_CONTINUATION) + else if (status == PUSH_MSG_REPLY || status == PUSH_MSG_UPDATE || status == PUSH_MSG_CONTINUATION) { c->options.push_option_types_found |= option_types_found;/* delay bringing tun/tap up until --push parms received from remote */ -if (status ==PUSH_MSG_REPLY ) +if (status ==PUSH_MSG_REPLY || status ==PUSH_MSG_UPDATE ) {if (!options_postprocess_pull (&c->options, c->c2.es)) { goto error; } -if (!do_up (c, true, c->options.push_option_types_found)) +if (status ==PUSH_MSG_REPLY ) { -msg (D_PUSH_ERRORS ,"Failed to open tun/tap interface" ); - goto error; +if (!do_up (c, true, c->options.push_option_types_found)) + { +msg (D_PUSH_ERRORS ,"Failed to open tun/tap interface" ); + goto error; + } + } +else + { +if (!option_types_found) + { +msg (M_WARN ,"No option found" ); + } } }event_timeout_clear (&c->c2.push_request_interval);
@@ -1048,11 +1056,13 @@md_ctx_init (c->c2.pulled_options_state,"SHA256" ); c->c2.pulled_options_digest_init_done = true; } -if (apply_push_options (&c->options, +if (apply_push_options (c, + &c->options, buf, permission_mask, option_types_found, - c->c2.es)) + c->c2.es, + false)) {push_update_digest (c->c2.pulled_options_state, &buf_orig, &c->options);
@@ -1103,6 +1113,12 @@return process_incoming_push_reply (c, permission_mask, option_types_found, &buf); } +else if (honor_received_options + &&buf_string_compare_advance (&buf, push_update_cmd)) + { +return process_incoming_push_update (c, permission_mask, + option_types_found, &buf); + }else {return PUSH_MSG_ERROR ;
src/openvpn/push.h +33 -0
@@ -33,9 +33,42 @@#define PUSH_MSG_AUTH_FAILURE 4#define PUSH_MSG_CONTINUATION 5#define PUSH_MSG_ALREADY_REPLIED 6 +#define PUSH_MSG_UPDATE 7 + +#define push_reply_cmd "PUSH_REPLY" +#define push_update_cmd "PUSH_UPDATE" + +/* Push-update options flags */ +#define PUSH_OPT_TO_REMOVE (1<<0) +#define PUSH_OPT_OPTIONAL (1<<1)int process_incoming_push_request (struct context *c); +/** +* @brief Handles the receiving of a push-update message and applies updates to the specified options. +* +* This function processes a push-update message, validating its content and applying updates +* to the options specified in the message. It also handles split messages if the complete +* message has not yet been received. +* +* @param c The context for the operation. +* @param permission_mask The permission mask specifying which options are allowed to be pulled. +* @param option_types_found A pointer to a variable that will be filled with the types of options +* found in the message. +* @param buf A buffer containing the received message. +* +* @return +* - `PUSH_MSG_UPDATE`: The message was processed successfully, and the updates were applied. +* - `PUSH_MSG_CONTINUATION`: The message is a fragment of a larger message, and the program is +* waiting for the final part. +* - `PUSH_MSG_ERROR`: An error occurred during message processing, or the message is invalid. +*/ + +int process_incoming_push_update (struct context *c, +unsigned int permission_mask, +unsigned int *option_types_found, +struct buffer *buf); + int process_incoming_push_msg(struct context *c, const struct buffer *buffer, bool honor_received_options,
src/openvpn/push_util.c new file +44 -0
44 lines not on this page · raw message
src/openvpn/ssl.c +3 -0
@@ -1947,6 +1947,9 @@/* support for exit notify via control channel */ iv_proto |=IV_PROTO_CC_EXIT_NOTIFY ; +/* support push-updates */ + iv_proto |=IV_PROTO_PUSH_UPDATE ; +if (session->opt->pull) {/* support for receiving push_reply before sending
src/openvpn/ssl.h +3 -0
@@ -110,6 +110,9 @@/** Supports the --dns option after all the incompatible changes */ #define IV_PROTO_DNS_OPTION_V2 (1<<11) +/** Supports push-update */ +#define IV_PROTO_PUSH_UPDATE (1<<12) +/* Default field in X509 to be username */ #define X509_USERNAME_FIELD_DEFAULT "CN"
tests/unit_tests/openvpn/Makefile.am +19 -1
@@ -11,7 +11,7 @@ endif test_binaries += crypto_testdriver packet_id_testdriver auth_token_testdriver ncp_testdriver misc_testdriver \ - pkt_testdriver ssl_testdriver user_pass_testdriver + pkt_testdriver ssl_testdriver user_pass_testdriver push_update_msg_testdriver if HAVE_LD_WRAP_SUPPORT if !WIN32
@@ -307,3 +307,21 @@ $(top_srcdir)/src/openvpn/win32-util.c \ $(top_srcdir)/src/openvpn/platform.c \ $(top_srcdir)/src/openvpn/list.c + +push_update_msg_testdriver_CFLAGS = -I$(top_srcdir)/src/openvpn \ + -I$(top_srcdir)/src/compat \ + -I$(top_srcdir)/tests/unit_tests/openvpn \ + @TEST_CFLAGS@ + +push_update_msg_testdriver_LDFLAGS = \ + @TEST_LDFLAGS@ \ + -L$(top_srcdir)/src/openvpn + +push_update_msg_testdriver_SOURCES = test_push_update_msg.c \ + mock_msg.c \ + mock_get_random.c \ + $(top_srcdir)/src/openvpn/buffer.c \ + $(top_srcdir)/src/openvpn/platform.c \ + $(top_srcdir)/src/openvpn/push_util.c \ + $(top_srcdir)/src/openvpn/options_util.c \ + $(top_srcdir)/src/openvpn/otime.c
tests/unit_tests/openvpn/test_push_update_msg.c new file +245 -0
245 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 6
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: stipa <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld, plaisthos, stipa.
mrbff has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/808?usp=email )
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
Patch Set 5:
(2 comments)
File CMakeLists.txt:
http://gerrit.openvpn.net/c/openvpn/+/808/comment/d57bba5b_c9eabd40 :
PS4, Line 817: src/openvpn/platform.c
Quoted 1 line
buffer.candplatform.care always added by foreach loop above. So they are redundant here.
Done
File src/openvpn/options.h:
http://gerrit.openvpn.net/c/openvpn/+/808/comment/17c2f5d7_5fb82784 :
PS4, Line 791: #define PUF_TYPE_UNDEF 0 /** undefined filter type */
Quoted 1 line
You didn't resolve the conflict correctly when rebasing. Please copy the new code here.
you are right, sorry!
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 5
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: stipa <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Thu, 28 Nov 2024 15:57:36 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, mrbff, plaisthos.
stipa has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/808?usp=email )
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
Patch Set 6: Code-Review-1
(2 comments)
Patchset:
PS6:
I did a quick test and following doesn't work:
2024-11-29 11:11:30 us=656000 PUSH: Received control message: 'PUSH_UPDATE,ifconfig 10.8.0.4 255.255.255.0' 2024-11-29 11:11:30 us=656000 No option found 2024-11-29 11:12:48 us=265000 Closing ovpn-dco interface 2024-11-29 11:12:48 us=265000 NETSH: C:\Windows\system32\netsh.exe interface ipv4 delete dns 20 all 2024-11-29 11:12:48 us=421000 NETSH: C:\Windows\system32\netsh.exe interface ipv4 delete address 20 10.8.0.2 store=active 2024-11-29 11:12:48 us=609000 SIGTERM[hard,] received, process exiting
File src/openvpn/push.c:
http://gerrit.openvpn.net/c/openvpn/+/808/comment/8d650f48_e00d63e5 :
PS6, Line 543: msg(M_WARN, "No option found");
This warning is a bit confusing.
2024-11-29 10:58:57 us=140000 PUSH: Received control message: 'PUSH_UPDATE,-dns' 2024-11-29 10:58:57 us=140000 No option found
It is unclear what exactly does it mean and what user/admin is supposed to do with it.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 6
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mrbff <[email protected]...>
Gerrit-Comment-Date: Fri, 29 Nov 2024 10:39:54 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, plaisthos, stipa.
mrbff has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/808?usp=email )
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
Patch Set 6:
(1 comment)
File src/openvpn/push.c:
http://gerrit.openvpn.net/c/openvpn/+/808/comment/d1a9ecd3_e048bce9 :
PS6, Line 543: msg(M_WARN, "No option found");
Quoted 1 line
This warning is a bit confusing. […]
I put it to avoid that in case of a correct message but without updates (something like "PUSH_UPDATE,," or "PUSH_UPDATE,?something_not_updatable") there was a useless closing and reopening of the tun, but it is not a real error message, it is more of an info. I'm not even sure it is the correct way to handle it, what do you suggest?
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 6
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Fri, 29 Nov 2024 17:14:56 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: stipa <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, mrbff, plaisthos.
stipa has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/808?usp=email )
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
Patch Set 6:
(1 comment)
File src/openvpn/push.c:
http://gerrit.openvpn.net/c/openvpn/+/808/comment/b5d51f26_68cd5be8 :
PS6, Line 543: msg(M_WARN, "No option found");
Quoted 1 line
I put it to avoid that in case of a correct message but without updates (something like "
PUSH_UPDATE[…]
How about "No updatable options found in incoming PUSH_UPDATE message" - I think it is verbose enough to let user/admin know what has happened.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 6
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mrbff <[email protected]...>
Gerrit-Comment-Date: Tue, 03 Dec 2024 10:42:48 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: mrbff <[email protected]...>
Comment-In-Reply-To: stipa <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, plaisthos, stipa.
mrbff has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/808?usp=email )
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
Patch Set 6:
(1 comment)
File src/openvpn/push.c:
http://gerrit.openvpn.net/c/openvpn/+/808/comment/29711b30_ad673ff1 :
PS6, Line 543: msg(M_WARN, "No option found");
Quoted 1 line
How about "No updatable options found in incoming
PUSH_UPDATEmessage" - I think it is verbose enoug […]
Ok then!
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 6
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Tue, 03 Dec 2024 11:06:38 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: stipa <[email protected]...>
Comment-In-Reply-To: mrbff <[email protected]...>
Gerrit-MessageType: comment
mrbff has abandoned this change. ( http://gerrit.openvpn.net/c/openvpn/+/808?usp=email )
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
Abandoned
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 7
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: abandon
mrbff has restored this change. ( http://gerrit.openvpn.net/c/openvpn/+/808?usp=email )
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
Restored
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 7
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: restore
Attention is currently required from: stipa.
Hello flichtenheld, plaisthos, stipa,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
to look at the new patch set (#8).
The following approvals got outdated and were removed:
Code-Review-1 by stipa
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
* Added IV_PROTO_PUSH_UPDATE flag bit to support push-updates.
* Added process_incoming_push_update(), in a separate file to create tests more easily.
* Modified incoming_push_message(), process_incoming_push_msg(), apply_push_options(), apply_pull_filter() to process also push-update messages.
* Added the check_push_update_option_flags() function used in apply_pull_filter() to check options formatting inside push-update messages, if the options are updatables and to check for '?' and '-' flags that may be present in front of the options. The '-' flag is used to indicate that the option in question should be removed, while the '?' indicates that the option is optional and to do not generate errors if the client cannot update that option.
For more info you can read the RFC at https://github.com/OpenVPN/openvpn-rfc .
* Created some unit tests for the push-update message handling in test_push_update_msg.c.
---
M CMakeLists.txt
M src/openvpn/Makefile.am
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/options_util.c
M src/openvpn/options_util.h
M src/openvpn/push.c
M src/openvpn/push.h
A src/openvpn/push_util.c
M src/openvpn/ssl.c
M src/openvpn/ssl.h
M tests/unit_tests/openvpn/Makefile.am
A tests/unit_tests/openvpn/test_push_update_msg.c
15 files changed, 643 insertions(+), 112 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/08/808/8
CMakeLists.txt +10 -0
@@ -496,6 +496,7 @@ src/openvpn/ps.c src/openvpn/ps.h src/openvpn/push.c + src/openvpn/push_util.c src/openvpn/push.h src/openvpn/pushlist.h src/openvpn/reflect_filter.c
@@ -612,6 +613,7 @@ "test_provider" "test_ssl" "test_user_pass" + "test_push_update_msg" ) if (WIN32)
@@ -808,6 +810,14 @@ src/openvpn/run_command.c ) + target_sources(test_push_update_msg PRIVATE + tests/unit_tests/openvpn/mock_msg.c + tests/unit_tests/openvpn/mock_get_random.c + src/openvpn/push_util.c + src/openvpn/options_util.c + src/openvpn/otime.c + ) + if (TARGET test_argv) target_link_options(test_argv PRIVATE -Wl,--wrap=parse_line) target_sources(test_argv PRIVATE
src/openvpn/Makefile.am +1 -1
@@ -114,7 +114,7 @@ proto.c proto.h \ proxy.c proxy.h \ ps.c ps.h \ - push.c push.h \ + push.c push_util.c push.h \ pushlist.h \ reflect_filter.c reflect_filter.h \ reliable.c reliable.h \
src/openvpn/forward.c +1 -1
@@ -2031,7 +2031,7 @@ }/* check for incoming control messages on the control channel like -* push request/reply, or authentication failure and 2FA messages */ +* push request/reply/update, or authentication failure and 2FA messages */ if (tls_test_payload_len (c->c2.tls_multi) >0 ) {check_incoming_control_channel (c);
src/openvpn/init.c +2 -2
@@ -2030,8 +2030,8 @@/* possibly add routes */ if ((route_order (c->c1.tuntap) ==ROUTE_AFTER_TUN ) && (!c->options.route_delay_defined)) { -int status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); +bool status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); *error_flags |= (status ?0 :ISC_ROUTE_ERRORS ); }
src/openvpn/options.c +39 -96
159 lines not on this page · raw message
src/openvpn/options.h +31 -2
@@ -777,6 +777,33 @@#define MAN_CLIENT_AUTH_ENABLED (opt) (false)#endif +/* +* some PUSH_UPDATE options +*/ +#define OPT_P_U_ROUTE (1<<0) +#define OPT_P_U_ROUTE6 (1<<1) +#define OPT_P_U_DNS (1<<2) +#define OPT_P_U_DHCP (1<<3) +#define OPT_P_U_REDIR_GATEWAY (1<<4) + +struct pull_filter +{ +#define PUF_TYPE_UNDEF 0/**< undefined filter type */ +#define PUF_TYPE_ACCEPT 1/**< filter type to accept a matching option */ +#define PUF_TYPE_IGNORE 2/**< filter type to ignore a matching option */ +#define PUF_TYPE_REJECT 3/**< filter type to reject and trigger SIGUSR1 */ +int type; +int size; +char *pattern; +struct pull_filter *next; +}; + +struct pull_filter_list +{ +struct pull_filter *head; +struct pull_filter *tail; +}; + void parse_argv(struct options *options, const int argc, char *argv[],
@@ -845,11 +872,13 @@void pre_connect_restore (struct options *o,struct gc_arena *gc); -bool apply_push_options (struct options *options, +bool apply_push_options (struct context *c, +struct options *options,struct buffer *buf,unsigned int permission_mask,unsigned int *option_types_found, -struct env_set *es); +struct env_set *es, +bool is_update);void options_detach (struct options *o);
src/openvpn/options_util.c +173 -0
182 lines not on this page · raw message
src/openvpn/options_util.h +14 -0
@@ -30,4 +30,18 @@const char *parse_auth_failed_temp (struct options *o,const char *reason); +/** +* Filter an option line by all pull filters. +* +* If a match is found, the line is modified depending on +* the filter type, and returns true. If the filter type is +* reject, SIGUSR1 is triggered and the return value is false. +* In that case the caller must end the push processing. +*/ +bool +apply_pull_filter (const struct options *o, +char *line, +bool is_update, +unsigned int *push_update_option_flags); +#endif
src/openvpn/push.c +25 -9
@@ -39,8 +39,6 @@#include "ssl_util.h" #include "options_util.h" -static char push_reply_cmd[] ="PUSH_REPLY" ; -/* * Auth username/password *
@@ -519,21 +517,31 @@ {msg (D_PUSH_ERRORS ,"WARNING: Received bad push/pull message: %s" ,sanitize_control_message (BSTR (buffer), &gc)); } - else if (status == PUSH_MSG_REPLY || status == PUSH_MSG_CONTINUATION) + else if (status == PUSH_MSG_REPLY || status == PUSH_MSG_UPDATE || status == PUSH_MSG_CONTINUATION) { c->options.push_option_types_found |= option_types_found;/* delay bringing tun/tap up until --push parms received from remote */ -if (status ==PUSH_MSG_REPLY ) +if (status ==PUSH_MSG_REPLY || status ==PUSH_MSG_UPDATE ) {if (!options_postprocess_pull (&c->options, c->c2.es)) { goto error; } -if (!do_up (c, true, c->options.push_option_types_found)) +if (status ==PUSH_MSG_REPLY ) { -msg (D_PUSH_ERRORS ,"Failed to open tun/tap interface" ); - goto error; +if (!do_up (c, true, c->options.push_option_types_found)) + { +msg (D_PUSH_ERRORS ,"Failed to open tun/tap interface" ); + goto error; + } + } +else + { +if (!option_types_found) + { +msg (M_WARN ,"No updatable options found in incoming PUSH_UPDATE message" ); + } } }event_timeout_clear (&c->c2.push_request_interval);
@@ -1048,11 +1056,13 @@md_ctx_init (c->c2.pulled_options_state,"SHA256" ); c->c2.pulled_options_digest_init_done = true; } -if (apply_push_options (&c->options, +if (apply_push_options (c, + &c->options, buf, permission_mask, option_types_found, - c->c2.es)) + c->c2.es, + false)) {push_update_digest (c->c2.pulled_options_state, &buf_orig, &c->options);
@@ -1103,6 +1113,12 @@return process_incoming_push_reply (c, permission_mask, option_types_found, &buf); } +else if (honor_received_options + &&buf_string_compare_advance (&buf, push_update_cmd)) + { +return process_incoming_push_update (c, permission_mask, + option_types_found, &buf); + }else {return PUSH_MSG_ERROR ;
src/openvpn/push.h +33 -0
@@ -33,9 +33,42 @@#define PUSH_MSG_AUTH_FAILURE 4#define PUSH_MSG_CONTINUATION 5#define PUSH_MSG_ALREADY_REPLIED 6 +#define PUSH_MSG_UPDATE 7 + +#define push_reply_cmd "PUSH_REPLY" +#define push_update_cmd "PUSH_UPDATE" + +/* Push-update options flags */ +#define PUSH_OPT_TO_REMOVE (1<<0) +#define PUSH_OPT_OPTIONAL (1<<1)int process_incoming_push_request (struct context *c); +/** +* @brief Handles the receiving of a push-update message and applies updates to the specified options. +* +* This function processes a push-update message, validating its content and applying updates +* to the options specified in the message. It also handles split messages if the complete +* message has not yet been received. +* +* @param c The context for the operation. +* @param permission_mask The permission mask specifying which options are allowed to be pulled. +* @param option_types_found A pointer to a variable that will be filled with the types of options +* found in the message. +* @param buf A buffer containing the received message. +* +* @return +* - `PUSH_MSG_UPDATE`: The message was processed successfully, and the updates were applied. +* - `PUSH_MSG_CONTINUATION`: The message is a fragment of a larger message, and the program is +* waiting for the final part. +* - `PUSH_MSG_ERROR`: An error occurred during message processing, or the message is invalid. +*/ + +int process_incoming_push_update (struct context *c, +unsigned int permission_mask, +unsigned int *option_types_found, +struct buffer *buf); + int process_incoming_push_msg(struct context *c, const struct buffer *buffer, bool honor_received_options,
src/openvpn/push_util.c new file +44 -0
44 lines not on this page · raw message
src/openvpn/ssl.c +3 -0
@@ -1947,6 +1947,9 @@/* support for exit notify via control channel */ iv_proto |=IV_PROTO_CC_EXIT_NOTIFY ; +/* support push-updates */ + iv_proto |=IV_PROTO_PUSH_UPDATE ; +if (session->opt->pull) {/* support for receiving push_reply before sending
src/openvpn/ssl.h +3 -0
@@ -110,6 +110,9 @@/** Supports the --dns option after all the incompatible changes */ #define IV_PROTO_DNS_OPTION_V2 (1<<11) +/** Supports push-update */ +#define IV_PROTO_PUSH_UPDATE (1<<12) +/* Default field in X509 to be username */ #define X509_USERNAME_FIELD_DEFAULT "CN"
tests/unit_tests/openvpn/Makefile.am +19 -1
@@ -11,7 +11,7 @@ endif test_binaries += crypto_testdriver packet_id_testdriver auth_token_testdriver ncp_testdriver misc_testdriver \ - pkt_testdriver ssl_testdriver user_pass_testdriver + pkt_testdriver ssl_testdriver user_pass_testdriver push_update_msg_testdriver if HAVE_LD_WRAP_SUPPORT if !WIN32
@@ -307,3 +307,21 @@ $(top_srcdir)/src/openvpn/win32-util.c \ $(top_srcdir)/src/openvpn/platform.c \ $(top_srcdir)/src/openvpn/list.c + +push_update_msg_testdriver_CFLAGS = -I$(top_srcdir)/src/openvpn \ + -I$(top_srcdir)/src/compat \ + -I$(top_srcdir)/tests/unit_tests/openvpn \ + @TEST_CFLAGS@ + +push_update_msg_testdriver_LDFLAGS = \ + @TEST_LDFLAGS@ \ + -L$(top_srcdir)/src/openvpn + +push_update_msg_testdriver_SOURCES = test_push_update_msg.c \ + mock_msg.c \ + mock_get_random.c \ + $(top_srcdir)/src/openvpn/buffer.c \ + $(top_srcdir)/src/openvpn/platform.c \ + $(top_srcdir)/src/openvpn/push_util.c \ + $(top_srcdir)/src/openvpn/options_util.c \ + $(top_srcdir)/src/openvpn/otime.c
tests/unit_tests/openvpn/test_push_update_msg.c new file +245 -0
245 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 8
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: mrbff.
stipa has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/808?usp=email )
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
Patch Set 11: Code-Review+2
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 11
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: mrbff <[email protected]...>
Gerrit-Comment-Date: Wed, 22 Jan 2025 09:13:59 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: mrbff.
flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/808?usp=email )
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
Patch Set 11: Code-Review-1
(1 comment)
Patchset:
PS11:
Please rebase to solve conflict with 40518dc66d9d04e6ec7e04439d7a6bc7fd6ac20f in options_util.[ch]
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 11
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: mrbff <[email protected]...>
Gerrit-Comment-Date: Wed, 05 Mar 2025 12:56:40 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, mrbff, stipa.
Hello flichtenheld, plaisthos, stipa,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
to look at the new patch set (#12).
The following approvals got outdated and were removed:
Code-Review+2 by stipa, Code-Review-1 by flichtenheld
The change is no longer submittable: Code-Review and checks~ChecksSubmitRule are unsatisfied now.
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
* Added IV_PROTO_PUSH_UPDATE flag bit to support push-updates.
* Added process_incoming_push_update(), in a separate file to create tests more easily.
* Modified incoming_push_message(), process_incoming_push_msg(), apply_push_options(), apply_pull_filter() to process also push-update messages.
* Added the check_push_update_option_flags() function used in apply_pull_filter() to check options formatting inside push-update messages, if the options are updatables and to check for '?' and '-' flags that may be present in front of the options. The '-' flag is used to indicate that the option in question should be removed, while the '?' indicates that the option is optional and to do not generate errors if the client cannot update that option.
For more info you can read the RFC at https://github.com/OpenVPN/openvpn-rfc .
* Created some unit tests for the push-update message handling in test_push_update_msg.c.
---
M CMakeLists.txt
M src/openvpn/Makefile.am
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/options_util.c
M src/openvpn/options_util.h
M src/openvpn/push.c
M src/openvpn/push.h
A src/openvpn/push_util.c
M src/openvpn/ssl.c
M src/openvpn/ssl.h
M tests/unit_tests/openvpn/Makefile.am
A tests/unit_tests/openvpn/test_push_update_msg.c
15 files changed, 643 insertions(+), 112 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/08/808/12
CMakeLists.txt +10 -0
@@ -506,6 +506,7 @@ src/openvpn/ps.c src/openvpn/ps.h src/openvpn/push.c + src/openvpn/push_util.c src/openvpn/push.h src/openvpn/pushlist.h src/openvpn/reflect_filter.c
@@ -622,6 +623,7 @@ "test_provider" "test_ssl" "test_user_pass" + "test_push_update_msg" ) if (WIN32)
@@ -824,6 +826,14 @@ src/openvpn/run_command.c ) + target_sources(test_push_update_msg PRIVATE + tests/unit_tests/openvpn/mock_msg.c + tests/unit_tests/openvpn/mock_get_random.c + src/openvpn/push_util.c + src/openvpn/options_util.c + src/openvpn/otime.c + ) + if (TARGET test_argv) target_link_options(test_argv PRIVATE -Wl,--wrap=parse_line) target_sources(test_argv PRIVATE
src/openvpn/Makefile.am +1 -1
@@ -116,7 +116,7 @@ proto.c proto.h \ proxy.c proxy.h \ ps.c ps.h \ - push.c push.h \ + push.c push_util.c push.h \ pushlist.h \ reflect_filter.c reflect_filter.h \ reliable.c reliable.h \
src/openvpn/forward.c +1 -1
@@ -2038,7 +2038,7 @@ }/* check for incoming control messages on the control channel like -* push request/reply, or authentication failure and 2FA messages */ +* push request/reply/update, or authentication failure and 2FA messages */ if (tls_test_payload_len (c->c2.tls_multi) >0 ) {check_incoming_control_channel (c);
src/openvpn/init.c +2 -2
@@ -2048,8 +2048,8 @@/* possibly add routes */ if ((route_order (c->c1.tuntap) ==ROUTE_AFTER_TUN ) && (!c->options.route_delay_defined)) { -int status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); +bool status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); *error_flags |= (status ?0 :ISC_ROUTE_ERRORS ); }
src/openvpn/options.c +39 -96
159 lines not on this page · raw message
src/openvpn/options.h +31 -2
@@ -793,6 +793,33 @@#define MAN_CLIENT_AUTH_ENABLED (opt) (false)#endif +/* +* some PUSH_UPDATE options +*/ +#define OPT_P_U_ROUTE (1<<0) +#define OPT_P_U_ROUTE6 (1<<1) +#define OPT_P_U_DNS (1<<2) +#define OPT_P_U_DHCP (1<<3) +#define OPT_P_U_REDIR_GATEWAY (1<<4) + +struct pull_filter +{ +#define PUF_TYPE_UNDEF 0/**< undefined filter type */ +#define PUF_TYPE_ACCEPT 1/**< filter type to accept a matching option */ +#define PUF_TYPE_IGNORE 2/**< filter type to ignore a matching option */ +#define PUF_TYPE_REJECT 3/**< filter type to reject and trigger SIGUSR1 */ +int type; +int size; +char *pattern; +struct pull_filter *next; +}; + +struct pull_filter_list +{ +struct pull_filter *head; +struct pull_filter *tail; +}; + void parse_argv(struct options *options, const int argc, char *argv[],
@@ -861,11 +888,13 @@void pre_connect_restore (struct options *o,struct gc_arena *gc); -bool apply_push_options (struct options *options, +bool apply_push_options (struct context *c, +struct options *options,struct buffer *buf,unsigned int permission_mask,unsigned int *option_types_found, -struct env_set *es); +struct env_set *es, +bool is_update);void options_detach (struct options *o);
src/openvpn/options_util.c +173 -0
182 lines not on this page · raw message
src/openvpn/options_util.h +14 -0
@@ -50,4 +50,18 @@int atoi_warn (const char *str,int msglevel); +/** +* Filter an option line by all pull filters. +* +* If a match is found, the line is modified depending on +* the filter type, and returns true. If the filter type is +* reject, SIGUSR1 is triggered and the return value is false. +* In that case the caller must end the push processing. +*/ +bool +apply_pull_filter (const struct options *o, +char *line, +bool is_update, +unsigned int *push_update_option_flags); +#endif /* ifndef OPTIONS_UTIL_H_ */
src/openvpn/push.c +25 -9
@@ -39,8 +39,6 @@#include "ssl_util.h" #include "options_util.h" -static char push_reply_cmd[] ="PUSH_REPLY" ; -/* * Auth username/password *
@@ -519,21 +517,31 @@ {msg (D_PUSH_ERRORS ,"WARNING: Received bad push/pull message: %s" ,sanitize_control_message (BSTR (buffer), &gc)); } - else if (status == PUSH_MSG_REPLY || status == PUSH_MSG_CONTINUATION) + else if (status == PUSH_MSG_REPLY || status == PUSH_MSG_UPDATE || status == PUSH_MSG_CONTINUATION) { c->options.push_option_types_found |= option_types_found;/* delay bringing tun/tap up until --push parms received from remote */ -if (status ==PUSH_MSG_REPLY ) +if (status ==PUSH_MSG_REPLY || status ==PUSH_MSG_UPDATE ) {if (!options_postprocess_pull (&c->options, c->c2.es)) { goto error; } -if (!do_up (c, true, c->options.push_option_types_found)) +if (status ==PUSH_MSG_REPLY ) { -msg (D_PUSH_ERRORS ,"Failed to open tun/tap interface" ); - goto error; +if (!do_up (c, true, c->options.push_option_types_found)) + { +msg (D_PUSH_ERRORS ,"Failed to open tun/tap interface" ); + goto error; + } + } +else + { +if (!option_types_found) + { +msg (M_WARN ,"No updatable options found in incoming PUSH_UPDATE message" ); + } } }event_timeout_clear (&c->c2.push_request_interval);
@@ -1058,11 +1066,13 @@md_ctx_init (c->c2.pulled_options_state,"SHA256" ); c->c2.pulled_options_digest_init_done = true; } -if (apply_push_options (&c->options, +if (apply_push_options (c, + &c->options, buf, permission_mask, option_types_found, - c->c2.es)) + c->c2.es, + false)) {push_update_digest (c->c2.pulled_options_state, &buf_orig, &c->options);
@@ -1113,6 +1123,12 @@return process_incoming_push_reply (c, permission_mask, option_types_found, &buf); } +else if (honor_received_options + &&buf_string_compare_advance (&buf, push_update_cmd)) + { +return process_incoming_push_update (c, permission_mask, + option_types_found, &buf); + }else {return PUSH_MSG_ERROR ;
src/openvpn/push.h +33 -0
@@ -33,9 +33,42 @@#define PUSH_MSG_AUTH_FAILURE 4#define PUSH_MSG_CONTINUATION 5#define PUSH_MSG_ALREADY_REPLIED 6 +#define PUSH_MSG_UPDATE 7 + +#define push_reply_cmd "PUSH_REPLY" +#define push_update_cmd "PUSH_UPDATE" + +/* Push-update options flags */ +#define PUSH_OPT_TO_REMOVE (1<<0) +#define PUSH_OPT_OPTIONAL (1<<1)int process_incoming_push_request (struct context *c); +/** +* @brief Handles the receiving of a push-update message and applies updates to the specified options. +* +* This function processes a push-update message, validating its content and applying updates +* to the options specified in the message. It also handles split messages if the complete +* message has not yet been received. +* +* @param c The context for the operation. +* @param permission_mask The permission mask specifying which options are allowed to be pulled. +* @param option_types_found A pointer to a variable that will be filled with the types of options +* found in the message. +* @param buf A buffer containing the received message. +* +* @return +* - `PUSH_MSG_UPDATE`: The message was processed successfully, and the updates were applied. +* - `PUSH_MSG_CONTINUATION`: The message is a fragment of a larger message, and the program is +* waiting for the final part. +* - `PUSH_MSG_ERROR`: An error occurred during message processing, or the message is invalid. +*/ + +int process_incoming_push_update (struct context *c, +unsigned int permission_mask, +unsigned int *option_types_found, +struct buffer *buf); + int process_incoming_push_msg(struct context *c, const struct buffer *buffer, bool honor_received_options,
src/openvpn/push_util.c new file +44 -0
44 lines not on this page · raw message
src/openvpn/ssl.c +3 -0
@@ -1990,6 +1990,9 @@/* support for exit notify via control channel */ iv_proto |=IV_PROTO_CC_EXIT_NOTIFY ; +/* support push-updates */ + iv_proto |=IV_PROTO_PUSH_UPDATE ; +if (session->opt->pull) {/* support for receiving push_reply before sending
src/openvpn/ssl.h +3 -0
@@ -114,6 +114,9 @@/** Supports the --dns option after all the incompatible changes */ #define IV_PROTO_DNS_OPTION_V2 (1<<11) +/** Supports push-update */ +#define IV_PROTO_PUSH_UPDATE (1<<12) +/* Default field in X509 to be username */ #define X509_USERNAME_FIELD_DEFAULT "CN"
tests/unit_tests/openvpn/Makefile.am +19 -1
@@ -11,7 +11,7 @@ endif test_binaries += crypto_testdriver packet_id_testdriver auth_token_testdriver ncp_testdriver misc_testdriver \ - pkt_testdriver ssl_testdriver user_pass_testdriver + pkt_testdriver ssl_testdriver user_pass_testdriver push_update_msg_testdriver if HAVE_LD_WRAP_SUPPORT if !WIN32
@@ -314,3 +314,21 @@ $(top_srcdir)/src/openvpn/win32-util.c \ $(top_srcdir)/src/openvpn/platform.c \ $(top_srcdir)/src/openvpn/list.c + +push_update_msg_testdriver_CFLAGS = -I$(top_srcdir)/src/openvpn \ + -I$(top_srcdir)/src/compat \ + -I$(top_srcdir)/tests/unit_tests/openvpn \ + @TEST_CFLAGS@ + +push_update_msg_testdriver_LDFLAGS = \ + @TEST_LDFLAGS@ \ + -L$(top_srcdir)/src/openvpn + +push_update_msg_testdriver_SOURCES = test_push_update_msg.c \ + mock_msg.c \ + mock_get_random.c \ + $(top_srcdir)/src/openvpn/buffer.c \ + $(top_srcdir)/src/openvpn/platform.c \ + $(top_srcdir)/src/openvpn/push_util.c \ + $(top_srcdir)/src/openvpn/options_util.c \ + $(top_srcdir)/src/openvpn/otime.c
tests/unit_tests/openvpn/test_push_update_msg.c new file +245 -0
245 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 12
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Attention: mrbff <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld, stipa.
mrbff has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/808?usp=email )
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
Patch Set 12:
(1 comment)
Patchset:
PS11:
Quoted 1 line
Please rebase to solve conflict with
40518dc66d9d04e6ec7e04439d7a6bc7fd6ac20finoptions_util. […]
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 12
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Fri, 21 Mar 2025 04:58:28 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: cron2, flichtenheld, mrbff, stipa.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/808?usp=email )
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
Patch Set 19: Code-Review-1
Copied votes on follow-up patch sets have been updated:
* Code-Review-1 has been copied to patch set 20 (copy condition: "changekind:NO_CHANGE OR changekind:TRIVIAL_REBASE OR is:MIN").
(10 comments)
Patchset:
PS19:
So, I think this works and is sufficently save and efficient, but I'm and old man and like my lawn orderly... so as discussed on IRC, please adjust a few minor points.
File src/openvpn/options.c:
http://gerrit.openvpn.net/c/openvpn/+/808/comment/849fb9c1_8109d087 :
PS19, Line 5567: apply_push_options(struct options *options,
please do not move that one around in options.c, this makes comparing old/new harder without good benefit, also breaks git blame...
http://gerrit.openvpn.net/c/openvpn/+/808/comment/25512e6f_b2eb183f :
PS19, Line 5654:
so I would call check_push_update_option_flags() from here, possibly moving the "while isspace(*line) { line++; }" part up here as well. Then we can keep "apply_pull_filter()" focused on "pull filter", not dealing with a number of extra conditions... (just "is_update", see there)
File src/openvpn/options_util.c:
http://gerrit.openvpn.net/c/openvpn/+/808/comment/5c5cd074_1394fe2c :
PS19, Line 198: if (!line || !*line || !**line)
the use of a double pointer irritates me, because we never move the pointer, instead memmove() the buffer...
I think we should just do (*line)++ instead of the memmove() below - possibly also getting rid of the strlen(str) thing, or str altogether :-) - so keep the pointer, call it from apply_push_options() and accept a moving *line pointer.
Also, I'm not sure if "empty string" should be treated as false or just ignored (return true, that is) - the existing environment where apply_pull_filter() is used does not care for "empty lines".
A NULL pointer is a programming error that must never happen, so an ASSERT(line) is valid.
http://gerrit.openvpn.net/c/openvpn/+/808/comment/6ffca9a9_893ed859 :
PS19, Line 231:
If there is whitespace here (? route) we'll fail with pushed option is not updateable: ' route', if I'm not misreading it.
I'd document that "there must not be whitespace between the flag letters and the option" and then we could add an if (isspace(**line)) { complain; return false; } here... the documentation is important, the error handling not so much (as it will hit the return false anyway)
http://gerrit.openvpn.net/c/openvpn/+/808/comment/bc8b42ab_3cf0ba0c :
PS19, Line 252: msg(D_PUSH, "Pushed option is not updatable: '%s'", *line);
Maybe add an " Ignoring." to the string, so it's clear "this is informational, but not an error, and this is how we handle it"? Since the other one has "Restarting"...
http://gerrit.openvpn.net/c/openvpn/+/808/comment/ce24fecc_c0a39fcd :
PS19, Line 270: if (!o->pull_filter_list && !(is_update))
So, if we call check_push_update_option_flags() from outside, we do not need this extra dance, checking o->pull_filter_list twice...
http://gerrit.openvpn.net/c/openvpn/+/808/comment/8974bb49_5a803112 :
PS19, Line 276: while (isspace(*line))
It makes sense to move that upwards to apply_push_options(), before calling anything on the line. So both all functions called do not need to bother about leading whitespace.
http://gerrit.openvpn.net/c/openvpn/+/808/comment/8689afde_5d9ee877 :
PS19, Line 310: return true;
This duplication of the messages and return true looks a bit silly :-) - I would suggest to do
```
/* on PUSH_UPDATE, "reject" and "ignore" filters are treated the same */
else if ( (f->type == PUF_TYPE_IGNORE || is_update)
&& strncmp(line, f->pattern, f->size) == 0)
{
msg(D_PUSH, "Pushed option removed by filter: '%s'", line);
return true;
}
```File src/openvpn/push_util.c:
http://gerrit.openvpn.net/c/openvpn/+/808/comment/b8dd5363_84e249de :
PS19, Line 23: true))
Just for the record - this is the really-old-style OpenVPN formatting, which we no longer use. That said, I know it's the same as in process_incoming_push_reply(), so it makes sense to keep it the same, and then clang-format will change both at once.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 19
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mrbff <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Mon, 21 Jul 2025 18:08:07 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: cron2, flichtenheld, mrbff, stipa.
Hello cron2, flichtenheld, plaisthos, stipa,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
to look at the new patch set (#21).
The following approvals got outdated and were removed:
Code-Review-1 by cron2
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
* Added IV_PROTO_PUSH_UPDATE flag bit to support push-updates.
* Added process_incoming_push_update(), in a separate file to create tests more easily.
* Modified incoming_push_message(), process_incoming_push_msg(), apply_push_options(), apply_pull_filter() to process also push-update messages.
* Added the check_push_update_option_flags() function used in apply_pull_filter() to check options formatting inside push-update messages, if the options are updatables and to check for '?' and '-' flags that may be present in front of the options. The '-' flag is used to indicate that the option in question should be removed, while the '?' indicates that the option is optional and to do not generate errors if the client cannot update that option.
For more info you can read the RFC at https://github.com/OpenVPN/openvpn-rfc .
* Created some unit tests for the push-update message handling in test_push_update_msg.c.
---
M CMakeLists.txt
M src/openvpn/Makefile.am
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/options_util.c
M src/openvpn/options_util.h
M src/openvpn/push.c
M src/openvpn/push.h
A src/openvpn/push_util.c
M src/openvpn/ssl.c
M src/openvpn/ssl.h
M tests/unit_tests/openvpn/Makefile.am
A tests/unit_tests/openvpn/test_push_update_msg.c
15 files changed, 617 insertions(+), 89 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/08/808/21
CMakeLists.txt +10 -0
@@ -534,6 +534,7 @@ src/openvpn/ps.c src/openvpn/ps.h src/openvpn/push.c + src/openvpn/push_util.c src/openvpn/push.h src/openvpn/pushlist.h src/openvpn/reflect_filter.c
@@ -652,6 +653,7 @@ "test_provider" "test_ssl" "test_user_pass" + "test_push_update_msg" ) if (WIN32)
@@ -854,6 +856,14 @@ src/openvpn/run_command.c ) + target_sources(test_push_update_msg PRIVATE + tests/unit_tests/openvpn/mock_msg.c + tests/unit_tests/openvpn/mock_get_random.c + src/openvpn/push_util.c + src/openvpn/options_util.c + src/openvpn/otime.c + ) + if (TARGET test_argv) target_link_options(test_argv PRIVATE -Wl,--wrap=parse_line) target_sources(test_argv PRIVATE
src/openvpn/Makefile.am +1 -1
@@ -117,7 +117,7 @@ proto.c proto.h \ proxy.c proxy.h \ ps.c ps.h \ - push.c push.h \ + push.c push_util.c push.h \ pushlist.h \ reflect_filter.c reflect_filter.h \ reliable.c reliable.h \
src/openvpn/forward.c +1 -1
@@ -2064,7 +2064,7 @@ }/* check for incoming control messages on the control channel like -* push request/reply, or authentication failure and 2FA messages */ +* push request/reply/update, or authentication failure and 2FA messages */ if (tls_test_payload_len (c->c2.tls_multi) >0 ) {check_incoming_control_channel (c);
src/openvpn/init.c +2 -2
@@ -2051,8 +2051,8 @@/* possibly add routes */ if ((route_order (c->c1.tuntap) ==ROUTE_AFTER_TUN ) && (!c->options.route_delay_defined)) { -int status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); +bool status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); *error_flags |= (status ?0 :ISC_ROUTE_ERRORS ); }
src/openvpn/options.c +32 -73
136 lines not on this page · raw message
src/openvpn/options.h +31 -2
@@ -794,6 +794,33 @@#define MAN_CLIENT_AUTH_ENABLED (opt) (false)#endif +/* +* some PUSH_UPDATE options +*/ +#define OPT_P_U_ROUTE (1<<0) +#define OPT_P_U_ROUTE6 (1<<1) +#define OPT_P_U_DNS (1<<2) +#define OPT_P_U_DHCP (1<<3) +#define OPT_P_U_REDIR_GATEWAY (1<<4) + +struct pull_filter +{ +#define PUF_TYPE_UNDEF 0/**< undefined filter type */ +#define PUF_TYPE_ACCEPT 1/**< filter type to accept a matching option */ +#define PUF_TYPE_IGNORE 2/**< filter type to ignore a matching option */ +#define PUF_TYPE_REJECT 3/**< filter type to reject and trigger SIGUSR1 */ +int type; +int size; +char *pattern; +struct pull_filter *next; +}; + +struct pull_filter_list +{ +struct pull_filter *head; +struct pull_filter *tail; +}; + void parse_argv(struct options *options, const int argc, char *argv[],
@@ -862,11 +889,13 @@void pre_connect_restore (struct options *o,struct gc_arena *gc); -bool apply_push_options (struct options *options, +bool apply_push_options (struct context *c, +struct options *options,struct buffer *buf,unsigned int permission_mask,unsigned int *option_types_found, -struct env_set *es); +struct env_set *es, +bool is_update);void options_detach (struct options *o);
src/openvpn/options_util.c +110 -0
119 lines not on this page · raw message
src/openvpn/options_util.h +43 -0
47 lines not on this page · raw message
src/openvpn/push.c +25 -9
@@ -39,8 +39,6 @@#include "ssl_util.h" #include "options_util.h" -static char push_reply_cmd[] ="PUSH_REPLY" ; -/* * Auth username/password *
@@ -519,21 +517,31 @@ {msg (D_PUSH_ERRORS ,"WARNING: Received bad push/pull message: %s" ,sanitize_control_message (BSTR (buffer), &gc)); } - else if (status == PUSH_MSG_REPLY || status == PUSH_MSG_CONTINUATION) + else if (status == PUSH_MSG_REPLY || status == PUSH_MSG_UPDATE || status == PUSH_MSG_CONTINUATION) { c->options.push_option_types_found |= option_types_found;/* delay bringing tun/tap up until --push parms received from remote */ -if (status ==PUSH_MSG_REPLY ) +if (status ==PUSH_MSG_REPLY || status ==PUSH_MSG_UPDATE ) {if (!options_postprocess_pull (&c->options, c->c2.es)) { goto error; } -if (!do_up (c, true, c->options.push_option_types_found)) +if (status ==PUSH_MSG_REPLY ) { -msg (D_PUSH_ERRORS ,"Failed to open tun/tap interface" ); - goto error; +if (!do_up (c, true, c->options.push_option_types_found)) + { +msg (D_PUSH_ERRORS ,"Failed to open tun/tap interface" ); + goto error; + } + } +else + { +if (!option_types_found) + { +msg (M_WARN ,"No updatable options found in incoming PUSH_UPDATE message" ); + } } }event_timeout_clear (&c->c2.push_request_interval);
@@ -1056,11 +1064,13 @@md_ctx_init (c->c2.pulled_options_state,"SHA256" ); c->c2.pulled_options_digest_init_done = true; } -if (apply_push_options (&c->options, +if (apply_push_options (c, + &c->options, buf, permission_mask, option_types_found, - c->c2.es)) + c->c2.es, + false)) {push_update_digest (c->c2.pulled_options_state, &buf_orig, &c->options);
@@ -1111,6 +1121,12 @@return process_incoming_push_reply (c, permission_mask, option_types_found, &buf); } +else if (honor_received_options + &&buf_string_compare_advance (&buf, push_update_cmd)) + { +return process_incoming_push_update (c, permission_mask, + option_types_found, &buf); + }else {return PUSH_MSG_ERROR ;
src/openvpn/push.h +33 -0
@@ -33,9 +33,42 @@#define PUSH_MSG_AUTH_FAILURE 4#define PUSH_MSG_CONTINUATION 5#define PUSH_MSG_ALREADY_REPLIED 6 +#define PUSH_MSG_UPDATE 7 + +#define push_reply_cmd "PUSH_REPLY" +#define push_update_cmd "PUSH_UPDATE" + +/* Push-update options flags */ +#define PUSH_OPT_TO_REMOVE (1<<0) +#define PUSH_OPT_OPTIONAL (1<<1)int process_incoming_push_request (struct context *c); +/** +* @brief Handles the receiving of a push-update message and applies updates to the specified options. +* +* This function processes a push-update message, validating its content and applying updates +* to the options specified in the message. It also handles split messages if the complete +* message has not yet been received. +* +* @param c The context for the operation. +* @param permission_mask The permission mask specifying which options are allowed to be pulled. +* @param option_types_found A pointer to a variable that will be filled with the types of options +* found in the message. +* @param buf A buffer containing the received message. +* +* @return +* - `PUSH_MSG_UPDATE`: The message was processed successfully, and the updates were applied. +* - `PUSH_MSG_CONTINUATION`: The message is a fragment of a larger message, and the program is +* waiting for the final part. +* - `PUSH_MSG_ERROR`: An error occurred during message processing, or the message is invalid. +*/ + +int process_incoming_push_update (struct context *c, +unsigned int permission_mask, +unsigned int *option_types_found, +struct buffer *buf); + int process_incoming_push_msg(struct context *c, const struct buffer *buffer, bool honor_received_options,
src/openvpn/push_util.c new file +44 -0
44 lines not on this page · raw message
src/openvpn/ssl.c +3 -0
@@ -1993,6 +1993,9 @@/* support for exit notify via control channel */ iv_proto |=IV_PROTO_CC_EXIT_NOTIFY ; +/* support push-updates */ + iv_proto |=IV_PROTO_PUSH_UPDATE ; +if (session->opt->pull) {/* support for receiving push_reply before sending
src/openvpn/ssl.h +3 -0
@@ -114,6 +114,9 @@/** Supports the --dns option after all the incompatible changes */ #define IV_PROTO_DNS_OPTION_V2 (1<<11) +/** Supports push-update */ +#define IV_PROTO_PUSH_UPDATE (1<<12) +/* Default field in X509 to be username */ #define X509_USERNAME_FIELD_DEFAULT "CN"
tests/unit_tests/openvpn/Makefile.am +19 -1
@@ -11,7 +11,7 @@ endif test_binaries += crypto_testdriver packet_id_testdriver auth_token_testdriver ncp_testdriver misc_testdriver \ - pkt_testdriver ssl_testdriver user_pass_testdriver + pkt_testdriver ssl_testdriver user_pass_testdriver push_update_msg_testdriver if HAVE_LD_WRAP_SUPPORT if !WIN32
@@ -326,3 +326,21 @@ $(top_srcdir)/src/openvpn/win32-util.c \ $(top_srcdir)/src/openvpn/platform.c \ $(top_srcdir)/src/openvpn/list.c + +push_update_msg_testdriver_CFLAGS = -I$(top_srcdir)/src/openvpn \ + -I$(top_srcdir)/src/compat \ + -I$(top_srcdir)/tests/unit_tests/openvpn \ + @TEST_CFLAGS@ + +push_update_msg_testdriver_LDFLAGS = \ + @TEST_LDFLAGS@ \ + -L$(top_srcdir)/src/openvpn + +push_update_msg_testdriver_SOURCES = test_push_update_msg.c \ + mock_msg.c \ + mock_get_random.c \ + $(top_srcdir)/src/openvpn/buffer.c \ + $(top_srcdir)/src/openvpn/platform.c \ + $(top_srcdir)/src/openvpn/push_util.c \ + $(top_srcdir)/src/openvpn/options_util.c \ + $(top_srcdir)/src/openvpn/otime.c
tests/unit_tests/openvpn/test_push_update_msg.c new file +260 -0
260 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 21
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mrbff <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: cron2, flichtenheld, stipa.
mrbff has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/808?usp=email )
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
Patch Set 21:
(8 comments)
File src/openvpn/options.c:
http://gerrit.openvpn.net/c/openvpn/+/808/comment/0bc4e799_eafa8770 :
PS19, Line 5567: apply_push_options(struct options *options,
Quoted 1 line
please do not move that one around in options. […]
Done
http://gerrit.openvpn.net/c/openvpn/+/808/comment/010661f3_5e3b560e :
PS19, Line 5654:
Quoted 1 line
so I would call
check_push_update_option_flags()from here, possibly moving the "while isspace(*line […]
Done
File src/openvpn/options_util.c:
http://gerrit.openvpn.net/c/openvpn/+/808/comment/47b8a262_12fab17a :
PS19, Line 198: if (!line || !*line || !**line)
Quoted 1 line
the use of a double pointer irritates me, because we never move the pointer, instead
memmove()the […]
Done
http://gerrit.openvpn.net/c/openvpn/+/808/comment/8e312009_6f3eacc1 :
PS19, Line 231:
Quoted 1 line
If there is whitespace here (
? route) we'll fail with `pushed option is not updateable: ' route' […]
Done
http://gerrit.openvpn.net/c/openvpn/+/808/comment/a777b4e8_51887b18 :
PS19, Line 252: msg(D_PUSH, "Pushed option is not updatable: '%s'", *line);
Quoted 1 line
Maybe add an " Ignoring. […]
Done
http://gerrit.openvpn.net/c/openvpn/+/808/comment/b521c226_07b2309a :
PS19, Line 270: if (!o->pull_filter_list && !(is_update))
Quoted 1 line
So, if we call
check_push_update_option_flags()from outside, we do not need this extra dance, che […]
Done
http://gerrit.openvpn.net/c/openvpn/+/808/comment/4d43cf7c_4985502d :
PS19, Line 276: while (isspace(*line))
Quoted 1 line
It makes sense to move that upwards to
apply_push_options(), before calling anything on the line. […]
Done
http://gerrit.openvpn.net/c/openvpn/+/808/comment/a7cb08ef_9c354e3e :
PS19, Line 310: return true;
Quoted 1 line
This duplication of the messages and
return truelooks a bit silly :-) - I would suggest to do […]
Acknowledged
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 21
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Wed, 23 Jul 2025 17:11:24 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, mrbff, stipa.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/808?usp=email )
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
Patch Set 21: Code-Review-1
(3 comments)
Patchset:
PS21:
I'm fine with most of the new version, but I'm still not really happy with apply_push_options(). Sorry.
File src/openvpn/options.c:
http://gerrit.openvpn.net/c/openvpn/+/808/comment/f3fc7445_db3c4290 :
PS21, Line 5524: {
please get rid of this extra if() level. Both conditions are checked again inside, so this is not really adding anything but an indent level.
http://gerrit.openvpn.net/c/openvpn/+/808/comment/37cf1615_f21e2c77 :
PS21, Line 5532: || (options->pull_filter_list && !apply_pull_filter(options, &line[i])))
I find this very hard to understand, even if it's a bit more space-efficient than having two if() clauses with their own error handling - but the latter would make the whole flow easier to understand.
Maybe just leaving the option->pull_filter_list check inside apply_pull_filter() (as it was) would already make this easier to read. Yes, we'd waste a function call per received push-option, but this is not a critical code path.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 21
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mrbff <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Sun, 27 Jul 2025 12:19:36 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: cron2, flichtenheld, mrbff, stipa.
Hello cron2, flichtenheld, plaisthos, stipa,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
to look at the new patch set (#22).
The following approvals got outdated and were removed:
Code-Review-1 by cron2
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
* Added IV_PROTO_PUSH_UPDATE flag bit to support push-updates.
* Added process_incoming_push_update(), in a separate file to create tests more easily.
* Modified incoming_push_message(), process_incoming_push_msg(), apply_push_options(), apply_pull_filter() to process also push-update messages.
* Added the check_push_update_option_flags() function used in apply_pull_filter() to check options formatting inside push-update messages, if the options are updatables and to check for '?' and '-' flags that may be present in front of the options. The '-' flag is used to indicate that the option in question should be removed, while the '?' indicates that the option is optional and to do not generate errors if the client cannot update that option.
For more info you can read the RFC at https://github.com/OpenVPN/openvpn-rfc .
* Created some unit tests for the push-update message handling in test_push_update_msg.c.
---
M CMakeLists.txt
M src/openvpn/Makefile.am
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/options_util.c
M src/openvpn/options_util.h
M src/openvpn/push.c
M src/openvpn/push.h
A src/openvpn/push_util.c
M src/openvpn/ssl.c
M src/openvpn/ssl.h
M tests/unit_tests/openvpn/Makefile.am
A tests/unit_tests/openvpn/test_push_update_msg.c
15 files changed, 625 insertions(+), 88 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/08/808/22
CMakeLists.txt +10 -0
@@ -534,6 +534,7 @@ src/openvpn/ps.c src/openvpn/ps.h src/openvpn/push.c + src/openvpn/push_util.c src/openvpn/push.h src/openvpn/pushlist.h src/openvpn/reflect_filter.c
@@ -652,6 +653,7 @@ "test_provider" "test_ssl" "test_user_pass" + "test_push_update_msg" ) if (WIN32)
@@ -854,6 +856,14 @@ src/openvpn/run_command.c ) + target_sources(test_push_update_msg PRIVATE + tests/unit_tests/openvpn/mock_msg.c + tests/unit_tests/openvpn/mock_get_random.c + src/openvpn/push_util.c + src/openvpn/options_util.c + src/openvpn/otime.c + ) + if (TARGET test_argv) target_link_options(test_argv PRIVATE -Wl,--wrap=parse_line) target_sources(test_argv PRIVATE
src/openvpn/Makefile.am +1 -1
@@ -117,7 +117,7 @@ proto.c proto.h \ proxy.c proxy.h \ ps.c ps.h \ - push.c push.h \ + push.c push_util.c push.h \ pushlist.h \ reflect_filter.c reflect_filter.h \ reliable.c reliable.h \
src/openvpn/forward.c +1 -1
@@ -2064,7 +2064,7 @@ }/* check for incoming control messages on the control channel like -* push request/reply, or authentication failure and 2FA messages */ +* push request/reply/update, or authentication failure and 2FA messages */ if (tls_test_payload_len (c->c2.tls_multi) >0 ) {check_incoming_control_channel (c);
src/openvpn/init.c +2 -2
@@ -2051,8 +2051,8 @@/* possibly add routes */ if ((route_order (c->c1.tuntap) ==ROUTE_AFTER_TUN ) && (!c->options.route_delay_defined)) { -int status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); +bool status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); *error_flags |= (status ?0 :ISC_ROUTE_ERRORS ); }
src/openvpn/options.c +35 -72
139 lines not on this page · raw message
src/openvpn/options.h +31 -2
@@ -794,6 +794,33 @@#define MAN_CLIENT_AUTH_ENABLED (opt) (false)#endif +/* +* some PUSH_UPDATE options +*/ +#define OPT_P_U_ROUTE (1<<0) +#define OPT_P_U_ROUTE6 (1<<1) +#define OPT_P_U_DNS (1<<2) +#define OPT_P_U_DHCP (1<<3) +#define OPT_P_U_REDIR_GATEWAY (1<<4) + +struct pull_filter +{ +#define PUF_TYPE_UNDEF 0/**< undefined filter type */ +#define PUF_TYPE_ACCEPT 1/**< filter type to accept a matching option */ +#define PUF_TYPE_IGNORE 2/**< filter type to ignore a matching option */ +#define PUF_TYPE_REJECT 3/**< filter type to reject and trigger SIGUSR1 */ +int type; +int size; +char *pattern; +struct pull_filter *next; +}; + +struct pull_filter_list +{ +struct pull_filter *head; +struct pull_filter *tail; +}; + void parse_argv(struct options *options, const int argc, char *argv[],
@@ -862,11 +889,13 @@void pre_connect_restore (struct options *o,struct gc_arena *gc); -bool apply_push_options (struct options *options, +bool apply_push_options (struct context *c, +struct options *options,struct buffer *buf,unsigned int permission_mask,unsigned int *option_types_found, -struct env_set *es); +struct env_set *es, +bool is_update);void options_detach (struct options *o);
src/openvpn/options_util.c +115 -0
124 lines not on this page · raw message
src/openvpn/options_util.h +43 -0
47 lines not on this page · raw message
src/openvpn/push.c +25 -9
@@ -39,8 +39,6 @@#include "ssl_util.h" #include "options_util.h" -static char push_reply_cmd[] ="PUSH_REPLY" ; -/* * Auth username/password *
@@ -519,21 +517,31 @@ {msg (D_PUSH_ERRORS ,"WARNING: Received bad push/pull message: %s" ,sanitize_control_message (BSTR (buffer), &gc)); } - else if (status == PUSH_MSG_REPLY || status == PUSH_MSG_CONTINUATION) + else if (status == PUSH_MSG_REPLY || status == PUSH_MSG_UPDATE || status == PUSH_MSG_CONTINUATION) { c->options.push_option_types_found |= option_types_found;/* delay bringing tun/tap up until --push parms received from remote */ -if (status ==PUSH_MSG_REPLY ) +if (status ==PUSH_MSG_REPLY || status ==PUSH_MSG_UPDATE ) {if (!options_postprocess_pull (&c->options, c->c2.es)) { goto error; } -if (!do_up (c, true, c->options.push_option_types_found)) +if (status ==PUSH_MSG_REPLY ) { -msg (D_PUSH_ERRORS ,"Failed to open tun/tap interface" ); - goto error; +if (!do_up (c, true, c->options.push_option_types_found)) + { +msg (D_PUSH_ERRORS ,"Failed to open tun/tap interface" ); + goto error; + } + } +else + { +if (!option_types_found) + { +msg (M_WARN ,"No updatable options found in incoming PUSH_UPDATE message" ); + } } }event_timeout_clear (&c->c2.push_request_interval);
@@ -1056,11 +1064,13 @@md_ctx_init (c->c2.pulled_options_state,"SHA256" ); c->c2.pulled_options_digest_init_done = true; } -if (apply_push_options (&c->options, +if (apply_push_options (c, + &c->options, buf, permission_mask, option_types_found, - c->c2.es)) + c->c2.es, + false)) {push_update_digest (c->c2.pulled_options_state, &buf_orig, &c->options);
@@ -1111,6 +1121,12 @@return process_incoming_push_reply (c, permission_mask, option_types_found, &buf); } +else if (honor_received_options + &&buf_string_compare_advance (&buf, push_update_cmd)) + { +return process_incoming_push_update (c, permission_mask, + option_types_found, &buf); + }else {return PUSH_MSG_ERROR ;
src/openvpn/push.h +33 -0
@@ -33,9 +33,42 @@#define PUSH_MSG_AUTH_FAILURE 4#define PUSH_MSG_CONTINUATION 5#define PUSH_MSG_ALREADY_REPLIED 6 +#define PUSH_MSG_UPDATE 7 + +#define push_reply_cmd "PUSH_REPLY" +#define push_update_cmd "PUSH_UPDATE" + +/* Push-update options flags */ +#define PUSH_OPT_TO_REMOVE (1<<0) +#define PUSH_OPT_OPTIONAL (1<<1)int process_incoming_push_request (struct context *c); +/** +* @brief Handles the receiving of a push-update message and applies updates to the specified options. +* +* This function processes a push-update message, validating its content and applying updates +* to the options specified in the message. It also handles split messages if the complete +* message has not yet been received. +* +* @param c The context for the operation. +* @param permission_mask The permission mask specifying which options are allowed to be pulled. +* @param option_types_found A pointer to a variable that will be filled with the types of options +* found in the message. +* @param buf A buffer containing the received message. +* +* @return +* - `PUSH_MSG_UPDATE`: The message was processed successfully, and the updates were applied. +* - `PUSH_MSG_CONTINUATION`: The message is a fragment of a larger message, and the program is +* waiting for the final part. +* - `PUSH_MSG_ERROR`: An error occurred during message processing, or the message is invalid. +*/ + +int process_incoming_push_update (struct context *c, +unsigned int permission_mask, +unsigned int *option_types_found, +struct buffer *buf); + int process_incoming_push_msg(struct context *c, const struct buffer *buffer, bool honor_received_options,
src/openvpn/push_util.c new file +44 -0
44 lines not on this page · raw message
src/openvpn/ssl.c +3 -0
@@ -1993,6 +1993,9 @@/* support for exit notify via control channel */ iv_proto |=IV_PROTO_CC_EXIT_NOTIFY ; +/* support push-updates */ + iv_proto |=IV_PROTO_PUSH_UPDATE ; +if (session->opt->pull) {/* support for receiving push_reply before sending
src/openvpn/ssl.h +3 -0
@@ -114,6 +114,9 @@/** Supports the --dns option after all the incompatible changes */ #define IV_PROTO_DNS_OPTION_V2 (1<<11) +/** Supports push-update */ +#define IV_PROTO_PUSH_UPDATE (1<<12) +/* Default field in X509 to be username */ #define X509_USERNAME_FIELD_DEFAULT "CN"
tests/unit_tests/openvpn/Makefile.am +19 -1
@@ -11,7 +11,7 @@ endif test_binaries += crypto_testdriver packet_id_testdriver auth_token_testdriver ncp_testdriver misc_testdriver \ - pkt_testdriver ssl_testdriver user_pass_testdriver + pkt_testdriver ssl_testdriver user_pass_testdriver push_update_msg_testdriver if HAVE_LD_WRAP_SUPPORT if !WIN32
@@ -326,3 +326,21 @@ $(top_srcdir)/src/openvpn/win32-util.c \ $(top_srcdir)/src/openvpn/platform.c \ $(top_srcdir)/src/openvpn/list.c + +push_update_msg_testdriver_CFLAGS = -I$(top_srcdir)/src/openvpn \ + -I$(top_srcdir)/src/compat \ + -I$(top_srcdir)/tests/unit_tests/openvpn \ + @TEST_CFLAGS@ + +push_update_msg_testdriver_LDFLAGS = \ + @TEST_LDFLAGS@ \ + -L$(top_srcdir)/src/openvpn + +push_update_msg_testdriver_SOURCES = test_push_update_msg.c \ + mock_msg.c \ + mock_get_random.c \ + $(top_srcdir)/src/openvpn/buffer.c \ + $(top_srcdir)/src/openvpn/platform.c \ + $(top_srcdir)/src/openvpn/push_util.c \ + $(top_srcdir)/src/openvpn/options_util.c \ + $(top_srcdir)/src/openvpn/otime.c
tests/unit_tests/openvpn/test_push_update_msg.c new file +260 -0
260 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 22
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mrbff <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: cron2, flichtenheld, stipa.
mrbff has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/808?usp=email )
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
Patch Set 21:
(2 comments)
File src/openvpn/options.c:
http://gerrit.openvpn.net/c/openvpn/+/808/comment/341dde0f_71ee184e :
PS21, Line 5524: {
Quoted 1 line
please get rid of this extra
if()level. […]
Done
http://gerrit.openvpn.net/c/openvpn/+/808/comment/005048a0_9d87b4c9 :
PS21, Line 5532: || (options->pull_filter_list && !apply_pull_filter(options, &line[i])))
Quoted 1 line
I find this very hard to understand, even if it's a bit more space-efficient than having two
if()[…]
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 21
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Mon, 28 Jul 2025 10:43:08 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, mrbff, stipa.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/808?usp=email )
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
Patch Set 22: Code-Review+2
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 22
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mrbff <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Tue, 29 Jul 2025 10:35:43 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
PATCH v22 1/1 PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
In reply to a message not in the archiveFrom: Marco Baffo <[email protected]...>
* Added IV_PROTO_PUSH_UPDATE flag bit to support push-updates.
* Added process_incoming_push_update(), in a separate file to create tests more easily.
* Modified incoming_push_message(), process_incoming_push_msg(), apply_push_options(), apply_pull_filter() to process also push-update messages.
* Added the check_push_update_option_flags() function used in apply_pull_filter() to check options formatting inside push-update messages, if the options are updatables and to check for '?' and '-' flags that may be present in front of the options. The '-' flag is used to indicate that the option in question should be removed, while the '?' indicates that the option is optional and to do not generate errors if the client cannot update that option.
For more info you can read the RFC at https://github.com/OpenVPN/openvpn-rfc .
* Created some unit tests for the push-update message handling in test_push_update_msg.c.
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/808
This mail reflects revision 22 of this Change.
Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>
CMakeLists.txt +10 -0
@@ -534,6 +534,7 @@ src/openvpn/ps.c src/openvpn/ps.h src/openvpn/push.c + src/openvpn/push_util.c src/openvpn/push.h src/openvpn/pushlist.h src/openvpn/reflect_filter.c
@@ -652,6 +653,7 @@ "test_provider" "test_ssl" "test_user_pass" + "test_push_update_msg" ) if (WIN32)
@@ -854,6 +856,14 @@ src/openvpn/run_command.c ) + target_sources(test_push_update_msg PRIVATE + tests/unit_tests/openvpn/mock_msg.c + tests/unit_tests/openvpn/mock_get_random.c + src/openvpn/push_util.c + src/openvpn/options_util.c + src/openvpn/otime.c + ) + if (TARGET test_argv) target_link_options(test_argv PRIVATE -Wl,--wrap=parse_line) target_sources(test_argv PRIVATE
src/openvpn/Makefile.am +1 -1
@@ -117,7 +117,7 @@ proto.c proto.h \ proxy.c proxy.h \ ps.c ps.h \ - push.c push.h \ + push.c push_util.c push.h \ pushlist.h \ reflect_filter.c reflect_filter.h \ reliable.c reliable.h \
src/openvpn/forward.c +1 -1
@@ -2064,7 +2064,7 @@ }/* check for incoming control messages on the control channel like -* push request/reply, or authentication failure and 2FA messages */ +* push request/reply/update, or authentication failure and 2FA messages */ if (tls_test_payload_len (c->c2.tls_multi) >0 ) {check_incoming_control_channel (c);
src/openvpn/init.c +2 -2
@@ -2051,8 +2051,8 @@/* possibly add routes */ if ((route_order (c->c1.tuntap) ==ROUTE_AFTER_TUN ) && (!c->options.route_delay_defined)) { -int status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); +bool status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); *error_flags |= (status ?0 :ISC_ROUTE_ERRORS ); }
src/openvpn/options.c +35 -72
139 lines not on this page · raw message
src/openvpn/options.h +31 -2
@@ -794,6 +794,33 @@#define MAN_CLIENT_AUTH_ENABLED (opt) (false)#endif +/* +* some PUSH_UPDATE options +*/ +#define OPT_P_U_ROUTE (1<<0) +#define OPT_P_U_ROUTE6 (1<<1) +#define OPT_P_U_DNS (1<<2) +#define OPT_P_U_DHCP (1<<3) +#define OPT_P_U_REDIR_GATEWAY (1<<4) + +struct pull_filter +{ +#define PUF_TYPE_UNDEF 0/**< undefined filter type */ +#define PUF_TYPE_ACCEPT 1/**< filter type to accept a matching option */ +#define PUF_TYPE_IGNORE 2/**< filter type to ignore a matching option */ +#define PUF_TYPE_REJECT 3/**< filter type to reject and trigger SIGUSR1 */ +int type; +int size; +char *pattern; +struct pull_filter *next; +}; + +struct pull_filter_list +{ +struct pull_filter *head; +struct pull_filter *tail; +}; + void parse_argv(struct options *options, const int argc, char *argv[],
@@ -862,11 +889,13 @@void pre_connect_restore (struct options *o,struct gc_arena *gc); -bool apply_push_options (struct options *options, +bool apply_push_options (struct context *c, +struct options *options,struct buffer *buf,unsigned int permission_mask,unsigned int *option_types_found, -struct env_set *es); +struct env_set *es, +bool is_update);void options_detach (struct options *o);
src/openvpn/options_util.c +115 -0
124 lines not on this page · raw message
src/openvpn/options_util.h +43 -0
47 lines not on this page · raw message
src/openvpn/push.c +25 -9
@@ -39,8 +39,6 @@#include "ssl_util.h" #include "options_util.h" -static char push_reply_cmd[] ="PUSH_REPLY" ; -/* * Auth username/password *
@@ -519,21 +517,31 @@ {msg (D_PUSH_ERRORS ,"WARNING: Received bad push/pull message: %s" ,sanitize_control_message (BSTR (buffer), &gc)); } - else if (status == PUSH_MSG_REPLY || status == PUSH_MSG_CONTINUATION) + else if (status == PUSH_MSG_REPLY || status == PUSH_MSG_UPDATE || status == PUSH_MSG_CONTINUATION) { c->options.push_option_types_found |= option_types_found;/* delay bringing tun/tap up until --push parms received from remote */ -if (status ==PUSH_MSG_REPLY ) +if (status ==PUSH_MSG_REPLY || status ==PUSH_MSG_UPDATE ) {if (!options_postprocess_pull (&c->options, c->c2.es)) { goto error; } -if (!do_up (c, true, c->options.push_option_types_found)) +if (status ==PUSH_MSG_REPLY ) { -msg (D_PUSH_ERRORS ,"Failed to open tun/tap interface" ); - goto error; +if (!do_up (c, true, c->options.push_option_types_found)) + { +msg (D_PUSH_ERRORS ,"Failed to open tun/tap interface" ); + goto error; + } + } +else + { +if (!option_types_found) + { +msg (M_WARN ,"No updatable options found in incoming PUSH_UPDATE message" ); + } } }event_timeout_clear (&c->c2.push_request_interval);
@@ -1056,11 +1064,13 @@md_ctx_init (c->c2.pulled_options_state,"SHA256" ); c->c2.pulled_options_digest_init_done = true; } -if (apply_push_options (&c->options, +if (apply_push_options (c, + &c->options, buf, permission_mask, option_types_found, - c->c2.es)) + c->c2.es, + false)) {push_update_digest (c->c2.pulled_options_state, &buf_orig, &c->options);
@@ -1111,6 +1121,12 @@return process_incoming_push_reply (c, permission_mask, option_types_found, &buf); } +else if (honor_received_options + &&buf_string_compare_advance (&buf, push_update_cmd)) + { +return process_incoming_push_update (c, permission_mask, + option_types_found, &buf); + }else {return PUSH_MSG_ERROR ;
src/openvpn/push.h +33 -0
@@ -33,9 +33,42 @@#define PUSH_MSG_AUTH_FAILURE 4#define PUSH_MSG_CONTINUATION 5#define PUSH_MSG_ALREADY_REPLIED 6 +#define PUSH_MSG_UPDATE 7 + +#define push_reply_cmd "PUSH_REPLY" +#define push_update_cmd "PUSH_UPDATE" + +/* Push-update options flags */ +#define PUSH_OPT_TO_REMOVE (1<<0) +#define PUSH_OPT_OPTIONAL (1<<1)int process_incoming_push_request (struct context *c); +/** +* @brief Handles the receiving of a push-update message and applies updates to the specified options. +* +* This function processes a push-update message, validating its content and applying updates +* to the options specified in the message. It also handles split messages if the complete +* message has not yet been received. +* +* @param c The context for the operation. +* @param permission_mask The permission mask specifying which options are allowed to be pulled. +* @param option_types_found A pointer to a variable that will be filled with the types of options +* found in the message. +* @param buf A buffer containing the received message. +* +* @return +* - `PUSH_MSG_UPDATE`: The message was processed successfully, and the updates were applied. +* - `PUSH_MSG_CONTINUATION`: The message is a fragment of a larger message, and the program is +* waiting for the final part. +* - `PUSH_MSG_ERROR`: An error occurred during message processing, or the message is invalid. +*/ + +int process_incoming_push_update (struct context *c, +unsigned int permission_mask, +unsigned int *option_types_found, +struct buffer *buf); + int process_incoming_push_msg(struct context *c, const struct buffer *buffer, bool honor_received_options,
src/openvpn/push_util.c new file +44 -0
44 lines not on this page · raw message
src/openvpn/ssl.c +3 -0
@@ -1993,6 +1993,9 @@/* support for exit notify via control channel */ iv_proto |=IV_PROTO_CC_EXIT_NOTIFY ; +/* support push-updates */ + iv_proto |=IV_PROTO_PUSH_UPDATE ; +if (session->opt->pull) {/* support for receiving push_reply before sending
src/openvpn/ssl.h +3 -0
@@ -114,6 +114,9 @@/** Supports the --dns option after all the incompatible changes */ #define IV_PROTO_DNS_OPTION_V2 (1<<11) +/** Supports push-update */ +#define IV_PROTO_PUSH_UPDATE (1<<12) +/* Default field in X509 to be username */ #define X509_USERNAME_FIELD_DEFAULT "CN"
tests/unit_tests/openvpn/Makefile.am +19 -1
@@ -11,7 +11,7 @@ endif test_binaries += crypto_testdriver packet_id_testdriver auth_token_testdriver ncp_testdriver misc_testdriver \ - pkt_testdriver ssl_testdriver user_pass_testdriver + pkt_testdriver ssl_testdriver user_pass_testdriver push_update_msg_testdriver if HAVE_LD_WRAP_SUPPORT if !WIN32
@@ -326,3 +326,21 @@ $(top_srcdir)/src/openvpn/win32-util.c \ $(top_srcdir)/src/openvpn/platform.c \ $(top_srcdir)/src/openvpn/list.c + +push_update_msg_testdriver_CFLAGS = -I$(top_srcdir)/src/openvpn \ + -I$(top_srcdir)/src/compat \ + -I$(top_srcdir)/tests/unit_tests/openvpn \ + @TEST_CFLAGS@ + +push_update_msg_testdriver_LDFLAGS = \ + @TEST_LDFLAGS@ \ + -L$(top_srcdir)/src/openvpn + +push_update_msg_testdriver_SOURCES = test_push_update_msg.c \ + mock_msg.c \ + mock_get_random.c \ + $(top_srcdir)/src/openvpn/buffer.c \ + $(top_srcdir)/src/openvpn/platform.c \ + $(top_srcdir)/src/openvpn/push_util.c \ + $(top_srcdir)/src/openvpn/options_util.c \ + $(top_srcdir)/src/openvpn/otime.c
tests/unit_tests/openvpn/test_push_update_msg.c new file +260 -0
260 lines not on this page · raw message
[Openvpn-devel] [PATCH applied] Re: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
So, this has been quite a journey... (and thanks, Marco, for keeping your patience). Lev has tested and +2'ed v11, which was then lost in the "rebase / avoid conflict" for v12. Up to v20, only reviews, and then I asked for lots of stylistic / code organizational changes which then brought this up to v22...
I have stared a lot at the code, and I have run the full "normal client and server side test" bed on it. I have not actually tested incoming PUSH_UPDATE messages, so at this point I have good faith that this does what it is supposed to do - and I'm pretty sure that it does not break anything. Lev has given 808+809+810 another test run on the "modified community server" (thanks!), and Corp QA has been asked to test against OpenVPN Inc commercial server infrastructure (so we'll hear if it does not work).
(Staring again, I *did* find one thing we should fix, namely the amount of options passed to apply_push_options() now, but this can be done in a new patch)
My plan for future testing is to integrate this into the t_client/t_server testbeds, setting up one instance that will do PUSH_UPDATE to send over the routes that are needed for ping success - but this needs #869 and quite a bit of new "drive management interface" infrastructure to get done. Soon. *cough*.
Your patch has been applied to the master branch.
commit 80b62545881cbe39e813c85c23984e62aaa76860
Author: Marco Baffo Date: Tue Jul 29 12:40:39 2025 +0200
PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
Signed-off-by: Marco Baffo <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg32406.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
cron2 has uploaded a new patch set (#23) to the change originally created by mrbff. ( http://gerrit.openvpn.net/c/openvpn/+/808?usp=email )
The following approvals got outdated and were removed:
Code-Review+2 by cron2
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
* Added IV_PROTO_PUSH_UPDATE flag bit to support push-updates.
* Added process_incoming_push_update(), in a separate file to create tests more easily.
* Modified incoming_push_message(), process_incoming_push_msg(), apply_push_options(), apply_pull_filter() to process also push-update messages.
* Added the check_push_update_option_flags() function used in apply_pull_filter() to check options formatting inside push-update messages, if the options are updatables and to check for '?' and '-' flags that may be present in front of the options. The '-' flag is used to indicate that the option in question should be removed, while the '?' indicates that the option is optional and to do not generate errors if the client cannot update that option.
For more info you can read the RFC at https://github.com/OpenVPN/openvpn-rfc .
* Created some unit tests for the push-update message handling in test_push_update_msg.c.
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg32406.html
---
M CMakeLists.txt
M src/openvpn/Makefile.am
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/options_util.c
M src/openvpn/options_util.h
M src/openvpn/push.c
M src/openvpn/push.h
A src/openvpn/push_util.c
M src/openvpn/ssl.c
M src/openvpn/ssl.h
M tests/unit_tests/openvpn/Makefile.am
A tests/unit_tests/openvpn/test_push_update_msg.c
15 files changed, 625 insertions(+), 88 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/08/808/23
CMakeLists.txt +10 -0
@@ -534,6 +534,7 @@ src/openvpn/ps.c src/openvpn/ps.h src/openvpn/push.c + src/openvpn/push_util.c src/openvpn/push.h src/openvpn/pushlist.h src/openvpn/reflect_filter.c
@@ -652,6 +653,7 @@ "test_provider" "test_ssl" "test_user_pass" + "test_push_update_msg" ) if (WIN32)
@@ -854,6 +856,14 @@ src/openvpn/run_command.c ) + target_sources(test_push_update_msg PRIVATE + tests/unit_tests/openvpn/mock_msg.c + tests/unit_tests/openvpn/mock_get_random.c + src/openvpn/push_util.c + src/openvpn/options_util.c + src/openvpn/otime.c + ) + if (TARGET test_argv) target_link_options(test_argv PRIVATE -Wl,--wrap=parse_line) target_sources(test_argv PRIVATE
src/openvpn/Makefile.am +1 -1
@@ -117,7 +117,7 @@ proto.c proto.h \ proxy.c proxy.h \ ps.c ps.h \ - push.c push.h \ + push.c push_util.c push.h \ pushlist.h \ reflect_filter.c reflect_filter.h \ reliable.c reliable.h \
src/openvpn/forward.c +1 -1
@@ -2064,7 +2064,7 @@ }/* check for incoming control messages on the control channel like -* push request/reply, or authentication failure and 2FA messages */ +* push request/reply/update, or authentication failure and 2FA messages */ if (tls_test_payload_len (c->c2.tls_multi) >0 ) {check_incoming_control_channel (c);
src/openvpn/init.c +2 -2
@@ -2051,8 +2051,8 @@/* possibly add routes */ if ((route_order (c->c1.tuntap) ==ROUTE_AFTER_TUN ) && (!c->options.route_delay_defined)) { -int status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); +bool status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); *error_flags |= (status ?0 :ISC_ROUTE_ERRORS ); }
src/openvpn/options.c +35 -72
139 lines not on this page · raw message
src/openvpn/options.h +31 -2
@@ -794,6 +794,33 @@#define MAN_CLIENT_AUTH_ENABLED (opt) (false)#endif +/* +* some PUSH_UPDATE options +*/ +#define OPT_P_U_ROUTE (1<<0) +#define OPT_P_U_ROUTE6 (1<<1) +#define OPT_P_U_DNS (1<<2) +#define OPT_P_U_DHCP (1<<3) +#define OPT_P_U_REDIR_GATEWAY (1<<4) + +struct pull_filter +{ +#define PUF_TYPE_UNDEF 0/**< undefined filter type */ +#define PUF_TYPE_ACCEPT 1/**< filter type to accept a matching option */ +#define PUF_TYPE_IGNORE 2/**< filter type to ignore a matching option */ +#define PUF_TYPE_REJECT 3/**< filter type to reject and trigger SIGUSR1 */ +int type; +int size; +char *pattern; +struct pull_filter *next; +}; + +struct pull_filter_list +{ +struct pull_filter *head; +struct pull_filter *tail; +}; + void parse_argv(struct options *options, const int argc, char *argv[],
@@ -862,11 +889,13 @@void pre_connect_restore (struct options *o,struct gc_arena *gc); -bool apply_push_options (struct options *options, +bool apply_push_options (struct context *c, +struct options *options,struct buffer *buf,unsigned int permission_mask,unsigned int *option_types_found, -struct env_set *es); +struct env_set *es, +bool is_update);void options_detach (struct options *o);
src/openvpn/options_util.c +115 -0
124 lines not on this page · raw message
src/openvpn/options_util.h +43 -0
47 lines not on this page · raw message
src/openvpn/push.c +25 -9
@@ -39,8 +39,6 @@#include "ssl_util.h" #include "options_util.h" -static char push_reply_cmd[] ="PUSH_REPLY" ; -/* * Auth username/password *
@@ -519,21 +517,31 @@ {msg (D_PUSH_ERRORS ,"WARNING: Received bad push/pull message: %s" ,sanitize_control_message (BSTR (buffer), &gc)); } - else if (status == PUSH_MSG_REPLY || status == PUSH_MSG_CONTINUATION) + else if (status == PUSH_MSG_REPLY || status == PUSH_MSG_UPDATE || status == PUSH_MSG_CONTINUATION) { c->options.push_option_types_found |= option_types_found;/* delay bringing tun/tap up until --push parms received from remote */ -if (status ==PUSH_MSG_REPLY ) +if (status ==PUSH_MSG_REPLY || status ==PUSH_MSG_UPDATE ) {if (!options_postprocess_pull (&c->options, c->c2.es)) { goto error; } -if (!do_up (c, true, c->options.push_option_types_found)) +if (status ==PUSH_MSG_REPLY ) { -msg (D_PUSH_ERRORS ,"Failed to open tun/tap interface" ); - goto error; +if (!do_up (c, true, c->options.push_option_types_found)) + { +msg (D_PUSH_ERRORS ,"Failed to open tun/tap interface" ); + goto error; + } + } +else + { +if (!option_types_found) + { +msg (M_WARN ,"No updatable options found in incoming PUSH_UPDATE message" ); + } } }event_timeout_clear (&c->c2.push_request_interval);
@@ -1056,11 +1064,13 @@md_ctx_init (c->c2.pulled_options_state,"SHA256" ); c->c2.pulled_options_digest_init_done = true; } -if (apply_push_options (&c->options, +if (apply_push_options (c, + &c->options, buf, permission_mask, option_types_found, - c->c2.es)) + c->c2.es, + false)) {push_update_digest (c->c2.pulled_options_state, &buf_orig, &c->options);
@@ -1111,6 +1121,12 @@return process_incoming_push_reply (c, permission_mask, option_types_found, &buf); } +else if (honor_received_options + &&buf_string_compare_advance (&buf, push_update_cmd)) + { +return process_incoming_push_update (c, permission_mask, + option_types_found, &buf); + }else {return PUSH_MSG_ERROR ;
src/openvpn/push.h +33 -0
@@ -33,9 +33,42 @@#define PUSH_MSG_AUTH_FAILURE 4#define PUSH_MSG_CONTINUATION 5#define PUSH_MSG_ALREADY_REPLIED 6 +#define PUSH_MSG_UPDATE 7 + +#define push_reply_cmd "PUSH_REPLY" +#define push_update_cmd "PUSH_UPDATE" + +/* Push-update options flags */ +#define PUSH_OPT_TO_REMOVE (1<<0) +#define PUSH_OPT_OPTIONAL (1<<1)int process_incoming_push_request (struct context *c); +/** +* @brief Handles the receiving of a push-update message and applies updates to the specified options. +* +* This function processes a push-update message, validating its content and applying updates +* to the options specified in the message. It also handles split messages if the complete +* message has not yet been received. +* +* @param c The context for the operation. +* @param permission_mask The permission mask specifying which options are allowed to be pulled. +* @param option_types_found A pointer to a variable that will be filled with the types of options +* found in the message. +* @param buf A buffer containing the received message. +* +* @return +* - `PUSH_MSG_UPDATE`: The message was processed successfully, and the updates were applied. +* - `PUSH_MSG_CONTINUATION`: The message is a fragment of a larger message, and the program is +* waiting for the final part. +* - `PUSH_MSG_ERROR`: An error occurred during message processing, or the message is invalid. +*/ + +int process_incoming_push_update (struct context *c, +unsigned int permission_mask, +unsigned int *option_types_found, +struct buffer *buf); + int process_incoming_push_msg(struct context *c, const struct buffer *buffer, bool honor_received_options,
src/openvpn/push_util.c new file +44 -0
44 lines not on this page · raw message
src/openvpn/ssl.c +3 -0
@@ -1993,6 +1993,9 @@/* support for exit notify via control channel */ iv_proto |=IV_PROTO_CC_EXIT_NOTIFY ; +/* support push-updates */ + iv_proto |=IV_PROTO_PUSH_UPDATE ; +if (session->opt->pull) {/* support for receiving push_reply before sending
src/openvpn/ssl.h +3 -0
@@ -114,6 +114,9 @@/** Supports the --dns option after all the incompatible changes */ #define IV_PROTO_DNS_OPTION_V2 (1<<11) +/** Supports push-update */ +#define IV_PROTO_PUSH_UPDATE (1<<12) +/* Default field in X509 to be username */ #define X509_USERNAME_FIELD_DEFAULT "CN"
tests/unit_tests/openvpn/Makefile.am +19 -1
@@ -11,7 +11,7 @@ endif test_binaries += crypto_testdriver packet_id_testdriver auth_token_testdriver ncp_testdriver misc_testdriver \ - pkt_testdriver ssl_testdriver user_pass_testdriver + pkt_testdriver ssl_testdriver user_pass_testdriver push_update_msg_testdriver if HAVE_LD_WRAP_SUPPORT if !WIN32
@@ -326,3 +326,21 @@ $(top_srcdir)/src/openvpn/win32-util.c \ $(top_srcdir)/src/openvpn/platform.c \ $(top_srcdir)/src/openvpn/list.c + +push_update_msg_testdriver_CFLAGS = -I$(top_srcdir)/src/openvpn \ + -I$(top_srcdir)/src/compat \ + -I$(top_srcdir)/tests/unit_tests/openvpn \ + @TEST_CFLAGS@ + +push_update_msg_testdriver_LDFLAGS = \ + @TEST_LDFLAGS@ \ + -L$(top_srcdir)/src/openvpn + +push_update_msg_testdriver_SOURCES = test_push_update_msg.c \ + mock_msg.c \ + mock_get_random.c \ + $(top_srcdir)/src/openvpn/buffer.c \ + $(top_srcdir)/src/openvpn/platform.c \ + $(top_srcdir)/src/openvpn/push_util.c \ + $(top_srcdir)/src/openvpn/options_util.c \ + $(top_srcdir)/src/openvpn/otime.c
tests/unit_tests/openvpn/test_push_update_msg.c new file +260 -0
260 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 23
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset
cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/808?usp=email )
Change subject: PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
......................................................................
PUSH_UPDATE: Allow OpenVPN in client mode to receive and handle PUSH UPDATE control messages to allow options updating at runtime.
* Added IV_PROTO_PUSH_UPDATE flag bit to support push-updates.
* Added process_incoming_push_update(), in a separate file to create tests more easily.
* Modified incoming_push_message(), process_incoming_push_msg(), apply_push_options(), apply_pull_filter() to process also push-update messages.
* Added the check_push_update_option_flags() function used in apply_pull_filter() to check options formatting inside push-update messages, if the options are updatables and to check for '?' and '-' flags that may be present in front of the options. The '-' flag is used to indicate that the option in question should be removed, while the '?' indicates that the option is optional and to do not generate errors if the client cannot update that option.
For more info you can read the RFC at https://github.com/OpenVPN/openvpn-rfc .
* Created some unit tests for the push-update message handling in test_push_update_msg.c.
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg32406.html
---
M CMakeLists.txt
M src/openvpn/Makefile.am
M src/openvpn/forward.c
M src/openvpn/init.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/options_util.c
M src/openvpn/options_util.h
M src/openvpn/push.c
M src/openvpn/push.h
A src/openvpn/push_util.c
M src/openvpn/ssl.c
M src/openvpn/ssl.h
M tests/unit_tests/openvpn/Makefile.am
A tests/unit_tests/openvpn/test_push_update_msg.c
15 files changed, 625 insertions(+), 88 deletions(-)
CMakeLists.txt +10 -0
@@ -534,6 +534,7 @@ src/openvpn/ps.c src/openvpn/ps.h src/openvpn/push.c + src/openvpn/push_util.c src/openvpn/push.h src/openvpn/pushlist.h src/openvpn/reflect_filter.c
@@ -652,6 +653,7 @@ "test_provider" "test_ssl" "test_user_pass" + "test_push_update_msg" ) if (WIN32)
@@ -854,6 +856,14 @@ src/openvpn/run_command.c ) + target_sources(test_push_update_msg PRIVATE + tests/unit_tests/openvpn/mock_msg.c + tests/unit_tests/openvpn/mock_get_random.c + src/openvpn/push_util.c + src/openvpn/options_util.c + src/openvpn/otime.c + ) + if (TARGET test_argv) target_link_options(test_argv PRIVATE -Wl,--wrap=parse_line) target_sources(test_argv PRIVATE
src/openvpn/Makefile.am +1 -1
@@ -117,7 +117,7 @@ proto.c proto.h \ proxy.c proxy.h \ ps.c ps.h \ - push.c push.h \ + push.c push_util.c push.h \ pushlist.h \ reflect_filter.c reflect_filter.h \ reliable.c reliable.h \
src/openvpn/forward.c +1 -1
@@ -2064,7 +2064,7 @@ }/* check for incoming control messages on the control channel like -* push request/reply, or authentication failure and 2FA messages */ +* push request/reply/update, or authentication failure and 2FA messages */ if (tls_test_payload_len (c->c2.tls_multi) >0 ) {check_incoming_control_channel (c);
src/openvpn/init.c +2 -2
@@ -2051,8 +2051,8 @@/* possibly add routes */ if ((route_order (c->c1.tuntap) ==ROUTE_AFTER_TUN ) && (!c->options.route_delay_defined)) { -int status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, - c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); +bool status =do_route (&c->options, c->c1.route_list, c->c1.route_ipv6_list, + c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx); *error_flags |= (status ?0 :ISC_ROUTE_ERRORS ); }
src/openvpn/options.c +35 -72
139 lines not on this page · raw message
src/openvpn/options.h +31 -2
@@ -794,6 +794,33 @@#define MAN_CLIENT_AUTH_ENABLED (opt) (false)#endif +/* +* some PUSH_UPDATE options +*/ +#define OPT_P_U_ROUTE (1<<0) +#define OPT_P_U_ROUTE6 (1<<1) +#define OPT_P_U_DNS (1<<2) +#define OPT_P_U_DHCP (1<<3) +#define OPT_P_U_REDIR_GATEWAY (1<<4) + +struct pull_filter +{ +#define PUF_TYPE_UNDEF 0/**< undefined filter type */ +#define PUF_TYPE_ACCEPT 1/**< filter type to accept a matching option */ +#define PUF_TYPE_IGNORE 2/**< filter type to ignore a matching option */ +#define PUF_TYPE_REJECT 3/**< filter type to reject and trigger SIGUSR1 */ +int type; +int size; +char *pattern; +struct pull_filter *next; +}; + +struct pull_filter_list +{ +struct pull_filter *head; +struct pull_filter *tail; +}; + void parse_argv(struct options *options, const int argc, char *argv[],
@@ -862,11 +889,13 @@void pre_connect_restore (struct options *o,struct gc_arena *gc); -bool apply_push_options (struct options *options, +bool apply_push_options (struct context *c, +struct options *options,struct buffer *buf,unsigned int permission_mask,unsigned int *option_types_found, -struct env_set *es); +struct env_set *es, +bool is_update);void options_detach (struct options *o);
src/openvpn/options_util.c +115 -0
124 lines not on this page · raw message
src/openvpn/options_util.h +43 -0
47 lines not on this page · raw message
src/openvpn/push.c +25 -9
@@ -39,8 +39,6 @@#include "ssl_util.h" #include "options_util.h" -static char push_reply_cmd[] ="PUSH_REPLY" ; -/* * Auth username/password *
@@ -519,21 +517,31 @@ {msg (D_PUSH_ERRORS ,"WARNING: Received bad push/pull message: %s" ,sanitize_control_message (BSTR (buffer), &gc)); } - else if (status == PUSH_MSG_REPLY || status == PUSH_MSG_CONTINUATION) + else if (status == PUSH_MSG_REPLY || status == PUSH_MSG_UPDATE || status == PUSH_MSG_CONTINUATION) { c->options.push_option_types_found |= option_types_found;/* delay bringing tun/tap up until --push parms received from remote */ -if (status ==PUSH_MSG_REPLY ) +if (status ==PUSH_MSG_REPLY || status ==PUSH_MSG_UPDATE ) {if (!options_postprocess_pull (&c->options, c->c2.es)) { goto error; } -if (!do_up (c, true, c->options.push_option_types_found)) +if (status ==PUSH_MSG_REPLY ) { -msg (D_PUSH_ERRORS ,"Failed to open tun/tap interface" ); - goto error; +if (!do_up (c, true, c->options.push_option_types_found)) + { +msg (D_PUSH_ERRORS ,"Failed to open tun/tap interface" ); + goto error; + } + } +else + { +if (!option_types_found) + { +msg (M_WARN ,"No updatable options found in incoming PUSH_UPDATE message" ); + } } }event_timeout_clear (&c->c2.push_request_interval);
@@ -1056,11 +1064,13 @@md_ctx_init (c->c2.pulled_options_state,"SHA256" ); c->c2.pulled_options_digest_init_done = true; } -if (apply_push_options (&c->options, +if (apply_push_options (c, + &c->options, buf, permission_mask, option_types_found, - c->c2.es)) + c->c2.es, + false)) {push_update_digest (c->c2.pulled_options_state, &buf_orig, &c->options);
@@ -1111,6 +1121,12 @@return process_incoming_push_reply (c, permission_mask, option_types_found, &buf); } +else if (honor_received_options + &&buf_string_compare_advance (&buf, push_update_cmd)) + { +return process_incoming_push_update (c, permission_mask, + option_types_found, &buf); + }else {return PUSH_MSG_ERROR ;
src/openvpn/push.h +33 -0
@@ -33,9 +33,42 @@#define PUSH_MSG_AUTH_FAILURE 4#define PUSH_MSG_CONTINUATION 5#define PUSH_MSG_ALREADY_REPLIED 6 +#define PUSH_MSG_UPDATE 7 + +#define push_reply_cmd "PUSH_REPLY" +#define push_update_cmd "PUSH_UPDATE" + +/* Push-update options flags */ +#define PUSH_OPT_TO_REMOVE (1<<0) +#define PUSH_OPT_OPTIONAL (1<<1)int process_incoming_push_request (struct context *c); +/** +* @brief Handles the receiving of a push-update message and applies updates to the specified options. +* +* This function processes a push-update message, validating its content and applying updates +* to the options specified in the message. It also handles split messages if the complete +* message has not yet been received. +* +* @param c The context for the operation. +* @param permission_mask The permission mask specifying which options are allowed to be pulled. +* @param option_types_found A pointer to a variable that will be filled with the types of options +* found in the message. +* @param buf A buffer containing the received message. +* +* @return +* - `PUSH_MSG_UPDATE`: The message was processed successfully, and the updates were applied. +* - `PUSH_MSG_CONTINUATION`: The message is a fragment of a larger message, and the program is +* waiting for the final part. +* - `PUSH_MSG_ERROR`: An error occurred during message processing, or the message is invalid. +*/ + +int process_incoming_push_update (struct context *c, +unsigned int permission_mask, +unsigned int *option_types_found, +struct buffer *buf); + int process_incoming_push_msg(struct context *c, const struct buffer *buffer, bool honor_received_options,
src/openvpn/push_util.c new file +44 -0
44 lines not on this page · raw message
src/openvpn/ssl.c +3 -0
@@ -1993,6 +1993,9 @@/* support for exit notify via control channel */ iv_proto |=IV_PROTO_CC_EXIT_NOTIFY ; +/* support push-updates */ + iv_proto |=IV_PROTO_PUSH_UPDATE ; +if (session->opt->pull) {/* support for receiving push_reply before sending
src/openvpn/ssl.h +3 -0
@@ -114,6 +114,9 @@/** Supports the --dns option after all the incompatible changes */ #define IV_PROTO_DNS_OPTION_V2 (1<<11) +/** Supports push-update */ +#define IV_PROTO_PUSH_UPDATE (1<<12) +/* Default field in X509 to be username */ #define X509_USERNAME_FIELD_DEFAULT "CN"
tests/unit_tests/openvpn/Makefile.am +19 -1
@@ -11,7 +11,7 @@ endif test_binaries += crypto_testdriver packet_id_testdriver auth_token_testdriver ncp_testdriver misc_testdriver \ - pkt_testdriver ssl_testdriver user_pass_testdriver + pkt_testdriver ssl_testdriver user_pass_testdriver push_update_msg_testdriver if HAVE_LD_WRAP_SUPPORT if !WIN32
@@ -326,3 +326,21 @@ $(top_srcdir)/src/openvpn/win32-util.c \ $(top_srcdir)/src/openvpn/platform.c \ $(top_srcdir)/src/openvpn/list.c + +push_update_msg_testdriver_CFLAGS = -I$(top_srcdir)/src/openvpn \ + -I$(top_srcdir)/src/compat \ + -I$(top_srcdir)/tests/unit_tests/openvpn \ + @TEST_CFLAGS@ + +push_update_msg_testdriver_LDFLAGS = \ + @TEST_LDFLAGS@ \ + -L$(top_srcdir)/src/openvpn + +push_update_msg_testdriver_SOURCES = test_push_update_msg.c \ + mock_msg.c \ + mock_get_random.c \ + $(top_srcdir)/src/openvpn/buffer.c \ + $(top_srcdir)/src/openvpn/platform.c \ + $(top_srcdir)/src/openvpn/push_util.c \ + $(top_srcdir)/src/openvpn/options_util.c \ + $(top_srcdir)/src/openvpn/otime.c
tests/unit_tests/openvpn/test_push_update_msg.c new file +260 -0
260 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/808?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6ecd4cb47571cc8c20e46de8595c742aeec6064a
Gerrit-Change-Number: 808
Gerrit-PatchSet: 23
Gerrit-Owner: mrbff <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged